-->
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.  [ 2 posts ] 
Author Message
 Post subject: Association and second level caching
PostPosted: Fri Dec 15, 2006 5:39 pm 
Newbie

Joined: Wed Oct 18, 2006 9:39 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Hi,

I have two POJOs "A" and "B". Both are marked as "lazy" and A to B is a one to one relation. I have marked the association as outer_join=true so B is always fetched.

Now consider the following scenario, when ehcache is enabled

1)First time Load "A". B is also loaded, and B is not "CGLIB" enahanced class. Both A and B are put in the second level cache

2)Once again load "A" in different transaction. Now "A" is loaded from ehcache. But "B" is not loaded. "B" is shown as "CGLIB" enhanced object in the debugger.

I have following questions
1) why is "B" CGLIB enhanced object when it is loaded from cache and regular object when it is loaded from DB.
2) How does ehache works for assoicated object? Are associated objects also loaded?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 5:58 am 
Newbie

Joined: Tue Dec 05, 2006 6:15 pm
Posts: 4
Location: London, England
I think it's a question of which logical layer the "fetch" plan relates to. As I understand it, "fetch" is mainly to tell Hibernate what SQL to generate when it goes to the database - not necessarily what plan to use when traversing the various caches.

So when neither A nor B are cached, and you're doing fetch=join, it will pull back both objects so there's no need to proxy/enhance B. However the second time you try, it finds A in the cache and so has to decide what to do about B. It sounds like although B is cached, Hibernate doesn't try and figure this out when it finds A - it will just wait until you try and access B before going off to look for it. (Presumably it will then find it in the 2nd level cache ok.) Maybe this is a result of your setting lazy to true ?(incidentally, if you want eager fetching why is lazy set to true ?)

As to why B is CGLib enhanced, is the association nullable ? There's a short section in the new Hibernate book (p.566) about lazy loading and one-one associations, where it says that unless "constrained=true" on the association, Hibernate can't know whether B is null or not without hitting the database, and so can't create a dymanic proxy. So to enable lazy loading - which is how you've configured it - it enhances the bytecode instead.

John

_________________
If you want IT, dowNinja IT.


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.