-->
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.  [ 3 posts ] 
Author Message
 Post subject: How TO: Deep copy instead of a reference (foreign key) value
PostPosted: Wed Feb 09, 2005 6:58 pm 
Newbie

Joined: Fri Aug 13, 2004 12:25 pm
Posts: 7
Location: Boston
Hibernate version: 2.1.7

Name and version of the database you are using: MySQL

Hi All.

I have two simple Hibernate bean classes: Fault.java and Revision.java

Fault class maps to FAULT table, and Revision class maps to REVISION table.

Fault.java contains these 3 properties:
int id (primary key)
String synopsis (nullable varchar)
Revision revision (not sure if I can do something like this)

Revision.java contains these 2 properties:
int id (primary key)
String title (nullable varchar)

I also have the HBM XML files for these two classes.

Note that 'revision' column in FAULT table references the primary key of REVISION table (IOW, FAULT.revision is a foreign key)

Now, is there an implicit way by which I can run a Hibernate query such as:
" select * from Fault "
and expect the returned Fault objects to contain Revision objects instead of just the reference. In other words, if I do the following:

List list = query.list();
for(Iterator itr = list.iterator(); itr.hasNext(); )
{
Fault fault = (Fault) itr.next();
Revision rev = fault.getRevision(); // ???
}


Would rev be a meaningful object with the values populated from the row refered to based on the foreign key in FAULT table?

If I can do something like this, can someone tell me how should my HBM XML files should look like? I tried using components, one-to-one and sets, but I get a null value everytime.

Thanks.
Kartik


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 09, 2005 7:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Of course you can (otherwise it'd be pretty pointless, huh?).

What you want is a many-to-one (just think in terms of the db relation cardinality).


Top
 Profile  
 
 Post subject: Perfect - works!
PostPosted: Wed Feb 09, 2005 10:09 pm 
Newbie

Joined: Fri Aug 13, 2004 12:25 pm
Posts: 7
Location: Boston
Thanks, Steve!

many-to-one is the key!

- Kartik


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