-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Lazy Instantiation Exception on Embedded object
PostPosted: Wed Jun 15, 2011 5:36 am 
Newbie

Joined: Wed Dec 19, 2007 6:49 am
Posts: 8
Location: London
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.