-->
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: Mapping a one to many without FKs
PostPosted: Wed Aug 31, 2005 10:37 am 
Newbie

Joined: Tue Aug 23, 2005 11:38 am
Posts: 14
I'm using hibernate 3.0.5 and I'm trying to create a 1 to m relationship with the <set tag. My parent class has a 1 column PK and so does my child, but they are different columns, hence the 1 to m. The child table does have an FK back to the parent, but I want to narrow the results more by adding another column to query that is in both table (adding to the join).

Does any one know how to do this?

I add another column to the <key tag but get an error saying that I have 2 columns defined in my key tag but the table only has 1 PK.

Thanks,


Top
 Profile  
 
 Post subject: Re: Mapping a one to many without FKs
PostPosted: Wed Aug 31, 2005 11:19 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
I would say it’s not possible to do what you described in the maps. I would solve this programmatically by using Criteria and Restrictions:

Code:
session.createCriteria(clazz).add(Restrictions.eq(“key”, value)).list();


This method would return a list of objects, where the key is the property name mapping to the column and the value is the value you are looking for.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 11:49 am 
Newbie

Joined: Tue Aug 23, 2005 11:38 am
Posts: 14
I was trying to hide that from the calling class (the main driver) and hide it in the xml definition file for the class in the one to many....

But this will work if I can't find anything else.

Thanks.


Top
 Profile  
 
 Post subject: named queries
PostPosted: Wed Aug 31, 2005 12:09 pm 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
An option could be to use named queries, which can be embedded in the map. Take a look at this link:

http://www.hibernate.org/hib_docs/v3/reference/en/html/objectstate.html#objectstate-querying-executing-named


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.