Hello there.
I have a problem on working with Hibernate. Actually, I've being working with it for a year. I know why TransientObjectException occurs, but if you follow me, maybe you will agree when I tell you this is weird and unjustifiable.
I have a class named CityVO with is perfectly mapped. I also have a class named AddressVO which is defined basically as follows:
Code:
@Entity
@Table(name = "ADDRESS", uniqueConstraints = {})
public class AddressVO {
private CityVO city;
@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_ID_CITY")
public CityVO getCity() {
if(isLazy() && this.city == null) {
this.city = new CityVO();
}
return this.city;
}
public void setCity(CityVO city) {
this.city = city;
}
}
Just to justify, this isLazy() method exists because a particularity on my application requires me to do that.
Well, everything works just finde. The problem is I got a very complex data importation process from Excel and I am having this error message:
Quote:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: br.com.singlepoint.crm.vo.CityVO
I thought that in some moment, my isLazy() was returning true and creating an instance of CityVO. But this is not true: while debugging, I realized this error occurs when I call the save() and flush() methods on Session, passing my AddressVO instance, and this instance's city attribute is null.
As long as know, this situation can't throw TransientObjectException. But it does. So my question is: what should I do?
Since now, I thank you all.[/quote]