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