-->
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: Mapping Question using generator class assigned
PostPosted: Thu Sep 02, 2004 12:41 am 
Newbie

Joined: Thu Sep 02, 2004 12:27 am
Posts: 1
I've the following class

[code]
public class Constraint {

private Long id;
// A reference to an external constraint.
private Constraint nextConstraint;
// Getters and setters
[/code]

The mapping document is defined as follows

[code]
<class
name="com.vidiator.businessobjects.Constraint"
table="vmdp_category">

<id name="id" column="id" type="long">
<generator class="native"/>
</id>

<many-to-one name="nextConstraint"
class="com.vidiator.businessobjects.Constraint"
column="next_constraint_id"
cascade="all"
/>
</class>
[/code]

In this model everything seems to work just as the documentation suggests. If i've a relationship estalblished with another object using nextConstraint in the DB i can see two objects persisted.

Now my questions :

1) I want to assign the primary keys myself and the documented approach to do this is to use the generator class "assigned". However when I run the same code the second tier objects are not being stored into the database. What am I doing wrong here?

2) I am migrating from JDO to use Hibernate (I seem to like it better), In JDO you have the concept of a JDO Identity where in the persistence engine will automatically add an ID field to you object and track it without having to explicitly declare the field as an attribute in the class. In my usecases this constraint class is always contained and I do not wish to explicitly track the ID field. From the documentation (well the hibernate in action book) i learnt that we can just specify the <id> element mapping as follows

[code]
<id column="id" type="long">
<generator class="native"/>
</id>
[/code]

This will prevent me from having to define the ID field explicitly as an attribute in the class. However due to the containment that I need to represent I am unable to get this to work. Is there anyway in which I can model this?

Your help is appreciated.

Regards,
Raj


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 2:27 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
for 1) see http://forum.hibernate.org/viewtopic.php?t=933521. Generally: don't use assigned id's if you don't have to.

for 2) I don't fully understand you problem, but may be a user type helps, see http://www.hibernate.org/50.html

HTH
Ernst


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.