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());