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: Save null value to many-to-one relationship error
PostPosted: Tue Oct 11, 2011 10:07 am 
Newbie

Joined: Tue Oct 11, 2011 9:55 am
Posts: 1
I have two classes Person and Department and there is a many-to-one relationship between Person and Department. The save operation is normal when there is a value applied to "department" of Person. When I want to save a null value to "department" of Person, there is the following error message.

object references an unsaved transient instance - save the transient instance before flushing: webmodule.model.Department; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: webmodule.model.Department

I doubt whether there are some settings missed for the classes. Please give help on this.

Class definition below:-
Code:
public class Person {
  private Integer id;
  private String name;
  private Department department;

  @ManyToOne(fetch=FetchType.EAGER, optional=true, targetEntity=Department.class)
  @NotFound(action=NotFoundAction.IGNORE)
  @JoinColumn(name="department", referencedColumnName="id", nullable=true, insertable=false, updatable=true)
  public Department getDepartment() {
    return department;
  }
  // other getter and setter
}

public class Department {
  private Integer id;
  private String name;
  // other getter and setter
}


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.