-->
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: TransientObjectException on a OneToOne association
PostPosted: Sun Jun 03, 2007 1:30 am 
Newbie

Joined: Sat Jun 02, 2007 11:24 pm
Posts: 1
Location: Austin, TX
I am pulling my hair (what little I have left) out trying to figure out why this code throws a TransientObjectException:
Code:
   public void update(Customer customer) {
      em.joinTransaction();
      em.merge(customer);     // exception thrown here
   }


The instance of Customer that I am passing into this method is a detached entity with a persisted address. The only thing that has been updated on this Customer instance is the lastName property (via a setter method).

The exception says:
Quote:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.bigbank.domain.Address


Here is the code for the Customer entity:
Code:
@Entity
public class Customer {
   @Id @GeneratedValue
   private int id;
   private String firstName;
   private String lastName;
   private String socialSecurityNumber;
   private Date dateOfBirth;
   @OneToMany(mappedBy = "customer", fetch = FetchType.EAGER)
   private Set<Account> accounts = new HashSet<Account>();
   @ManyToOne(cascade=CascadeType.ALL)
   private Bank bank;
   @OneToOne(cascade=CascadeType.ALL)
   private Address address;

   // implementation follows.....
}


Here is the code for the Address entity:
Code:
@Entity
public class Address {
   @Id @GeneratedValue
   private int id;
   private String line1;
   private String line2;
   private String city;
   private String state;
   private String postalCode;

   // implementation follows.....
}


The persist() method does insert the Customer and Address records as expected. Can anyone see what I am missing? Any help would be appreciated.

Thanks,

Tony


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 4:51 pm 
Newbie

Joined: Mon Jun 04, 2007 3:38 pm
Posts: 2
Location: Boston, MA
Does your Bank object has a reference to Address object ?


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.