-->
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.  [ 5 posts ] 
Author Message
 Post subject: Does the Hibernate PU allow multiple many to one ?
PostPosted: Tue Dec 09, 2008 12:10 pm 
Newbie

Joined: Tue Dec 09, 2008 11:55 am
Posts: 7
Hi .
can somebody to give me some idea?
a collection of folders belonging to a owner is many to one relationship so a collection of folders with one owner is ok but if a owner has two different collections; it should be ok, right? the annotation as folows:


I use the annotation in bean:
@ManyToOne ( targetEntity = research.utils.Member.class, optional=false )
@JoinColumn(name="owner", insertable=false, updatable=false, nullable=false)


for another collection in the same bean :

@ManyToOne ( targetEntity = research.utils.AdminMember.class, optional=false )
@JoinColumn(name="adminOwner", insertable=false, updatable=false, nullable=false)


however, when hibernate join table even it is " member" object , it still want to join " adminmember"


I use Sping as entitymanager to manage transaction ...

who can comment on this?

Thank you in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 2:56 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2008 10:15 am
Posts: 21
The example you provided is not very clear. To answer your main question, yes we can have multiple many-to-one relationships between two tables. But, you need to have two different varaibles in "Many" table to map to the same "one" table.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 4:02 pm 
Newbie

Joined: Tue Dec 09, 2008 11:55 am
Posts: 7
Thank you very much for your reply !
Yes , in " many" table(folder bean) , I have two collection of fields in this "Folder" bean and have two different owners: owner, type is "Member" and adminOwner, type is "AdminMember" the annotation is showing this ...

But after I login , when I want add a folder to the logined member's folders, no matter I logined as "Memebr" or " AdminMember" (THEY BELONG TO TWO TABLES RESPECTIVELY), hibernate always to join " adminMember " table ...

the annotation mapped to owner for the "Member" , why hibernate join " Adminmember owner? this the problem I want to solve..

if the annotation attributes I used is not proper?


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2008 4:34 pm 
Beginner
Beginner

Joined: Thu Oct 02, 2008 10:15 am
Posts: 21
Official Documentation
-------------------------
optional: If enabled (the default), Hibernate will insert a row only if the properties defined by this join are non-null and will always use an outer join to retrieve the properties.

Now, set optional=true in your annotations and you should see the join is not created in the SQL when the correcponding property is null.

Let me know if this works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2008 6:38 pm 
Newbie

Joined: Tue Dec 09, 2008 11:55 am
Posts: 7
Hi,
Thank you so much for your reply.
Right now, I have merged Adminmember and member as Member by add more column in one table. but still, when I start implemet Document part member will have more one collections corresponding several table at that time I will try ... I expect more help by then and I twill let you know the resul definitly...


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