-->
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: Beginner's Mapping Question
PostPosted: Thu Mar 09, 2006 12:06 pm 
Newbie

Joined: Thu Mar 09, 2006 11:52 am
Posts: 13
Hibernate version: 3.0
Name and version of the database you are using: MySQL 4.1.16-nt

I have a mapping question that should be easy to answer for the Hibernate cracks on this boards:

I want to map the following class:

Code:
public class Element
{
   protected Integer elementId;
   protected Element predecessorElement;
   [...]
}


My question is: How do I map the predecessorElement property. This is a reference to another Element object that serves as the base of the current object. The object may be null. Furthermore the predecessorElement may only have one Element that it precedes.

Basically this seems to be a one-to-one association with the exception that both the actual Element and its predecessors are stored in the same table (element).

Thanks in advance for your advice.

EDIT: I just realized that I accenditally posted in the wrong forum, shame on me... Would be nice if the mods could move this thread to the Hibernate Users forum.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 6:21 pm 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:07 am
Posts: 33
in your Element.hbm.xml file just write:
<many-to-one
name="Element"
class="com.mycompany.Element"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ELEMENT_ID"
/>

cascade/update and insert values are up to your model.

Please do not forget to vote.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 6:25 pm 
Newbie

Joined: Thu Mar 09, 2006 11:52 am
Posts: 13
Thanks, this seems to work, although I think it's a little weird because technically this isn't a many-to-one mapping, but screw it ;)


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.