-->
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: Object somtimes from the cache sometimes not
PostPosted: Tue Oct 07, 2008 3:37 pm 
Newbie

Joined: Wed Nov 08, 2006 2:30 pm
Posts: 6
Hi there,

I have an odd question. It is not a real problem, because I have a working work-around. But it is something that made me investigate a lot without any result.

Here is my problem:
I have a many-to-one relationship the is lazyly fetched.


Code:
    @ManyToOne(fetch = FetchType.LAZY, targetEntity = AbstractLibraryQuestion.class,
          cascade = { CascadeType.PERSIST, CascadeType.MERGE,
                              CascadeType.REFRESH })
    @JoinColumn(name = "LB_QSTN_ID")
    public T getLibraryQuestion() {
        return libraryQuestion;
    }



When I call this method getLibrbaryQuestion() I sometime get an object that has the concrete class AbstractLibraryQuestion and sometimes one that comes from the cache, where the class name is AbstractLibraryQuestion$$EnhancerByCGLIB$$9a9e8ce9

Here is my code how to deal with it:

Code:
        AbstractLibraryQuestion tmq;
        Object proxy = this.getLibraryQuestion();
        System.out.println("proxy.getClass().getName() = " + proxy.getClass().getName());
        if (proxy instanceof AbstractLibraryQuestion) {
            tmq = (AbstractLibraryQuestion) proxy;
        } else {
            tmq = AbstractLibraryQuestion.class.cast(((HibernateProxy) proxy).
                    getHibernateLazyInitializer().getImplementation());
        }


This works just fine, but I still would like to know why my object sometimes is cached and sometimes not.
I'd be happy about any information.
Thanks,
Johannes


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.