Hi,
I have an annotated entity class which has an embedded object representing on of the columns. I'm getting a org.hibernate.LazyInitializationException when I try to access that property but I can't figure out how to specify that I want that fetched eagerly.
Here's my code -
Code:
@Entity
@Table(name="ADDRESSBOOK_CONTACT")
public class Contact ......
...
.....
@Embedded
@AttributeOverrides(
@AttributeOverride(name="number", column = @Column(name="PHONE_NUMBER"))
)
private PhoneNumber phoneNumber;
public PhoneNumber getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(PhoneNumber phoneNumber) {
this.phoneNumber = phoneNumber;
}
And my PhoneNumber class
Code:
@Embeddable
public class PhoneNumber .......
When I call getPhoneNumber() outside the scope of the active session I get the following LIE
Code:
SEVERE: Servlet.service() for servlet messenger threw exception
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:108)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:150)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at com.hunsley.messenger.addressbook.Contact$$EnhancerByCGLIB$$71cd214c.getPhoneNumber(<generated>)
How do I tell hibernate that I want the phoneNumber property fetched eagerly? If it were not embedded I would use the @Basic() annotation and specify the fetch mode but there is no such property on the Embedded or Embeddable annotations.
Many thanks
John