Hi,
We have an address entity with the country entity embedded into it using @OneToOne unidirectional technique, CascadeType.REFRESH.
The issue is, on save or modify involving address, it expects the country object with the Version set along with the CountryId(The PK in Country which is the FK in Address table).
And it accepts any value even if it doesn't match with the original Version of the country object.
If version is not set, the save/modify fails with the error:
save transient object Country before Saving Address.
The code is given below.
Hibernate version:3.2.1.ga
Mapping documents:
Address entity:
@Entity
@Table(name="P_CRM_CLIENT_ADDRESS")
public class Address{
protected Long addressId;
protected String address;
protected Country countryObj;
//getters and setters for addressId and address
@OneToOne (cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinColumn(name = "COUNTRY_ID")
public Country getCountryObj() {
return countryObj;
}
public void setCountryObj(Country countryObj) {
this.countryObj = countryObj;
}
}
Country entity:
@Entity
@Table(name = "REF_COUNTRY")
public class Country
{
protected String countryId;
protected String countryDescription;
protected Long versionNo;
//getters and setters for countryId and countryDescription
@Version
@Column(name = "VER_NO")
public Long getVersionNo() {
return versionNo;
}
public void setVersionNo(Long versionNo) {
this.versionNo = versionNo;
}
}
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using: Oracle 10g
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Any help regarding this issue is appreciated.
Thanks
|