-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using the second level cache with multiple SessionFactories
PostPosted: Fri Nov 05, 2004 6:16 pm 
Newbie

Joined: Thu Sep 02, 2004 2:31 pm
Posts: 12
I am posting this to determine if I am incorrectly using Hibernate or if I have come across a potential bug.

I have fairly good sized object graph (around 30-40 classes when it's all loaded) and in order to be able to quickly display search results without having to create new objects, I created a second SessionFactory that only maps about 15 of the classes and only maps relevant fields for those classes. My DAO maintains two SessionFactories, the one with the partial mappings and another with the full mappings for displaying the entire graph. This worked fine for me until I ran into the case where an object had been loaded with the fully mapped SessionFactory and placed into the second level cache and then a Session created from the partially mapped SessionFactory attempted to load that object from the cache. In that case, I got the stack trace below.

I did not study all the code, but looking at CacheEntry.assemble, it appears that the values for cached objects are either stored in an array or loaded into array before creating a new instance of the class from the cached values. Again, just looking CacheEntry.assemble it appears that it iterates over the array of cached values placing them into another array sized according to the class mapping associated with the current SessionFactory. In my case, the partial mapping had one less field, so the ArrayIndexOutOfBoundsException was thrown. I confirmed that this was the problem first by changing both SessionFactories to use the fullmapping, in which case the test passed. Then I updated the mapping of the particular class in the partial mapping set to be the same as its fully mapped counterpart and that executed successfully as well.

So I found that I could solve my problem by ensuring that any class that would be cached must be mapped the same in all the SessionFactories, but I thought I would post this to see if:
1) My usage is incorrect
2) My usage is acceptable and the limitations of the cache are acceptable
3) The limitations with the cache could be considered a bug

If (2) is the case, is it possible that an exception could be thrown to indicate that Hibernate has detected incompatible mappings?

Thanks very much for your time.

Hibernate version: 2.1.6

Full stack trace of any exception that occurs:java.lang.ArrayIndexOutOfBoundsException: 5
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:56)
at net.sf.hibernate.impl.CacheEntry.assemble(CacheEntry.java:48)
at net.sf.hibernate.impl.SessionImpl.assembleCacheEntry(SessionImpl.java:2134)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2112)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1991)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1953)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:69)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:204)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2205)
at net.sf.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:315)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:305)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3613)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.vflic.cyberpar.datamapping.HibernateCyberPARDataMapper$PolicySearchCallback.doInHibernate(HibernateCyberPARDataMapper.java:342)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:200)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:220)
at com.vflic.cyberpar.datamapping.HibernateCyberPARDataMapper.findPolicies(HibernateCyberPARDataMapper.java:253)
at com.vflic.cyberpar.datamapping.CoverageEntityNameSearchTest.doTestFindByFirstAndLastName(CoverageEntityNameSearchTest.java:317)
at com.vflic.cyberpar.datamapping.CoverageEntityNameSearchTest.testEntityNameSearch(CoverageEntityNameSearchTest.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)


Name and version of the database you are using: Oracle 10g


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 8:18 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Use 2 different prefixes for you SF
Code:
hibernate.cache.region_prefix

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 10:39 am 
Newbie

Joined: Thu Sep 02, 2004 2:31 pm
Posts: 12
Thanks for your quick response. This is good example of all the the work and forethought you guys have put into Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 7:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
:-)
Thanks

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.