-->
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: order of insertions
PostPosted: Tue Mar 11, 2008 11:01 am 
Newbie

Joined: Thu Mar 24, 2005 6:32 am
Posts: 4
I am using hibernate core 3.2.6ga with hibernate annotations 3.2.1ga.
I have an object model with ~20 classes using 1:n bidirectional relations.
The model is ERM model is not "tree like", however has one root object.
Unlike tree, parent's grandchildren can have relation with 2 parent's children.
All relations are annotated like that:

Code:
@Entity
@Table (name="stack")
public class Stack
{
   private Section section;
   private JobColor color;
   // some other properties   
   
   Stack()
   {
   }

   @ManyToOne(optional=false) @Cascade(CascadeType.SAVE_UPDATE)
   @JoinColumn (name="section_id", nullable=false)
   public Section getSection()
   {
      return this.section;
   }
   
   void setSection(Section section)
   {
      this.section = section;
   }

   @ManyToOne(optional=false) @Cascade(CascadeType.SAVE_UPDATE)
   @JoinColumn (name="job_color_id", nullable=false)
   public JobColor getColor()
   {
      return color;
   }

   void setColor(JobColor color)
   {
      this.color = color;
   }
}


@Entity
@Table (name="section")
public class Section
{
   private Marker marker;
   private List<Stack> stacksList = new ArrayList<Stack>();
   // some other properties   
   
   Section()
   {
   }

   @ManyToOne @Cascade(CascadeType.SAVE_UPDATE)
   @JoinColumn (name="marker_id")
   public Marker getMarker()
   {
      return this.marker;
   }

   protected void setMarker(Marker marker)
   {
      this.marker = marker;
   }

   @OneToMany(mappedBy="section") @Cascade(CascadeType.ALL)
   List<Stack> getStackList()
   {
      return stacksList;
   }

   void setStackList(List<Stack> stacksList)
   {
      this.stacksList = stacksList;
   }
}


Problem is: when i create a complex object and call session.saveOrUpdate(parentObject),
i get error "not-null property references a null or transient value: Stack.section".
From cascade log i see SAVE_UPDATE event was properly cascaded to ALL objects.
However, my class Stack is going to be saved before Section.
This is bad, because Stack has
Code:
@JoinColumn (name="section_id", nullable=false)



My question is: can i expect hibernate will find proper order of insertions in a any complex graph "automatically" or i should ensure it "manually" under certain circumstances?


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.