-->
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.  [ 1 post ] 
Author Message
 Post subject: Associating children with Sequence-Generated id parent
PostPosted: Thu Jan 17, 2008 9:17 am 
Newbie

Joined: Sun Dec 30, 2007 3:58 pm
Posts: 7
Hibernate version:
3.2.4.GA
Mapping documents:
Annotated classes
Name and version of the database you are using:
Oracle 10g

Hello,

I am trying to persist a pretty complex object graph with hibernate(and Spring)

To simplify my question I'll avoid describing it fully,

The parent object Id is auto generated sequence and is annotated with

Code:
@Id
@Column(name = "ITEMIK", unique = true, nullable = false, insertable = true, updatable = true, precision = 10, scale = 0)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "itemid_seq")
@SequenceGenerator(name="itemid_seq", sequenceName = "ITEMID_SEQ")   


This Object has a one-to-many collection. getter annotated with

Code:
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "spiBu")



And finally, the child object has another OneToMany collection of some entity. So this is actually a "grandchild" which has a foreign keys to the (generated) ids of both its parent and its grandparent.
It also has an Id generated by a sequence, (same like its parent).

-------------

To create the graph I create the parent (new GrandParent() ) and then associate it with hibernate session (Using spring DAOSupport )

Then I create its children and grandchildren

Now, when the session flushed I'd expect to see that the
children will get the generated parent sequence (It is a foreign key constraint) and that the grandchildren will get the children generated sequence.
and the grandparent generated sequence.

But for some reason- The grandchildren is getting the "grandparent" sequence successfully , but It gets 0 for the parent id.
and fails on a foreign key constraint.

Note! I am doing the following:
---------------------------
Code:
//Explicit Internal Keys
grandChildren.getId().setGrandParent(GrandParent.getik());   

grandChildren.getId().setParent(Parent.getik());


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.