-->
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.  [ 2 posts ] 
Author Message
 Post subject: how to get manytoany to work
PostPosted: Mon Dec 14, 2009 11:53 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
I'm trying to specify a (only unidirectional right now) manytoany association, but I'm not able to make hibernate build a join table with a type column.

The class structure is like this
Code:
A(abstract)
|    \
B    C(abstract)
      |  \
      D  E


This is the annotation I am using for the manytoany association from B to C
Code:
@org.hibernate.annotations.ManyToAny(fetch = FetchType.EAGER, metaColumn = @Column(name = "C_Type"))
@org.hibernate.annotations.AnyMetaDef(idType = "string", metaType = "string", metaValues = {})
@JoinTable(name = "BtoC", joinColumns = @JoinColumn(name = "B_id"), inverseJoinColumns = @JoinColumn(name = "C_id"))


AFAIK I should get a join table "BtoC" with three columns:
Code:
B_id, C_id, C_Type

Instead the join table only contains:
Code:
B_id, C_id


This is with the TABLE_PER_CLASS and the JOINED InheritanceType. In case of TABLE_PER_CLASS it uses the unions to determine the "any"-end of the association instead of creating and using the "C_Type" column. What am I doing wrong?


Top
 Profile  
 
 Post subject: Re: how to get manytoany to work
PostPosted: Tue Dec 15, 2009 4:08 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
I guess the behaviour is actually expected. What threw me off was the documentation which says that a "ToAny" association always has one column for the id and one for the type...


Quote:
2.4.6.2.6. @ManyToAny

@ManyToAny allows polymorphic associations to classes from multiple tables. This type of mapping always requires more than one column. The first column holds the type of the associated entity. The remaining columns hold the identifier. It is impossible to specify a foreign key constraint for this kind of association, so this is most certainly not meant as the usual way of mapping (polymorphic) associations. You should use this only in very special cases (eg. audit logs, user session data, etc).


Instead it is using a union of the subclasses when using the table-per-class inheritancetype.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.