Dear all,
I have come across a problem which I was puzzled and need some help. I have a biz transaction table name "A" that reference a master table e.g. Country.
@Entity
public class A {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="COUNTRY_CODE",insertable=false,updatable=false)
private Country country;
@Column(name="COUNTRY_CODE")
private String countryCode;
...
@Entity
public class Country {
// no one to many association for A defined
...
Using entityManager.find(A.class, pk) to retrieve A entity instance allow me to lazy load my Country reference simply with a.getCountry().toString();
Whenever i have a detached A entity instance to be updated, I simply do:
A managedA = entityManager.merge(detachedA).
However, the instance returned: managedA doesn't trigger lazy loading of my country reference when i do managedA.getCountry().toString(); The country reference will always return null.
I have tried with entityManager.flush(); after the merge() operation and yet it still return null country reference. I was even puzzled further when i replaced flush() with entityManager.find() after the merged() operation, result remained the same with further disappointment.
I am not sure whether this is a problem of hibernate or is my approach to tackle this problem wasn't correct. Need some advice from fellow experts. Thanks in advance.
Hibernate version: 3.2.6.ga
_________________ Andy
|