-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: <any> mapping with Hibernate Annotations? (AnyType)
PostPosted: Tue Jul 04, 2006 12:53 pm 
Newbie

Joined: Sun Jun 04, 2006 4:19 pm
Posts: 9
Location: Germany
The <any> tag (Hibernate Core) seems to be a way how to implement polymorphic relations with the table-per-contrete-class strategy and a discriminator.

However, JPA/EJB 3.0 or some Hibernate Annotations specific extensions would be the prefered technology. So, the general question is if there is a way to use the <any> principle with JPA?

Some thoughts on this:

I know you could mix hbm.xml files with JPA Annotations, but there are some concerns using a mixture of "two" technologies in the project team.

Another alternative I would see is extending Hibernate Annotations ourselves - any ideas, comments or experiences on this approach?


Top
 Profile  
 
 Post subject: Re: <any> mapping with Hibernate Annotations? (AnyType
PostPosted: Tue Jul 04, 2006 2:46 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
markusoj wrote:
However, JPA/EJB 3.0 or some Hibernate Annotations specific extensions would be the prefered technology. So, the general question is if there is a way to use the <any> principle with JPA?

With plain JPA, hmm ... as you are aware, you can use it with H3 - which is JBoss JPA implementation ;-).

markusoj wrote:
I know you could mix hbm.xml files with JPA Annotations, but there are some concerns using a mixture of "two" technologies in the project team.

We use it - we have a lot of 'legacy' entities - which we don't feel like annotating - just extra work for entities that we use all the time - User, Address, Company, ...

markusoj wrote:
Another alternative I would see is extending Hibernate Annotations ourselves - any ideas, comments or experiences on this approach?

You can always submit a patch of additional Hibernate Annotations. :-)

Rgds, Ales


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 5:54 am 
Newbie

Joined: Sun Jun 04, 2006 4:19 pm
Posts: 9
Location: Germany
Thank you Ales for sharing your opinions. You said your experience with mixing JPA and Hibernate Core mechanisms was positive. Could you describe your solution a little more in detail (for which part are you using JPA?)

Also, I see some limitations of the <any> solution. OK, it does not fit in the EJB 3.0 forum, but since we started already...

First, I did not figure out yet how to use any with a join over multiple columns. The PK referenced by <any> is a composite-id:
<composite-id name="oid" class="SomeOid">
<key-property name="idH" column="H"/>
<key-property name="idM" column="M"/>
<key-property name="idL" column="L"/>
</composite-id>

The <any> mapping:
<any name="anyRel" id-type="SomeOid" meta-type="integer">
<meta-value value="1" class="Test1"/>
<meta-value value="2" class="Test2"/>
<meta-value value="3" class="Test3"/>
<column name="XyzC"/>
<column name="XyzH"/>
<column name="XyzM"/>
<column name="XyzL"/>
</any>
Like this, Hibernate has problem with the type:
org.hibernate.MappingException: property mapping has wrong number of columns: HasAny.anyRel type: object

I would have a CompositeUserType for the SomeOid class, but I could not find a syntax how to tell it Hibernate to use it for the <any> mapping.

Second, am I right that there is no way to define bidirectional association with <any> on one side?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 6:56 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
Could you describe your solution a little more in detail (for which part are you using JPA?)

We are mostly using Hibernate - with Session, SessionFactory, ... in enterprise beans with @PersistenceContext, @PersistenceUnit - as JPA is a subset of H3.
But we have a generic Session bean that uses EntityManager - which uses Java5 generics,when Session is not.

Quote:
Second, am I right that there is no way to define bidirectional association with <any> on one side?

Uf, never used <any>.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.