-->
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: second level cache not used in a complex legacy mapping
PostPosted: Wed May 10, 2006 10:54 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have a complex three table legacy mapping as follows. I am able to do the mapping and generate the needed SQL. The problem comes when I try to integrate second level caching. I have set the following properties in the hibernate properties file

hibernate.cache.use_second_level_cache true
hibernate.cache.use_query_cache true

Since I can't provide the full key and populate the primary key class, I am not able to use the Load() method or the get() method. I have to depend on query cache as I am providing partial key. When I try to test it, hibernate checks the query spaces for up-to-dateness and I get the debug message complaining that the
MemoryStore:204 - octts1.org.hibernate.cache.UpdateTimestampsCacheCache: MemoryStore miss for te_size
and then I get the exception specified
Can somebody let me know where I am going wrong?
I have used the second level cache sucessfully before for simple data persistance using get() method

|#]

Hibernate version:
3.1
Mapping documents:

<class
name="com.tradeentity.TeDefinition"
table="te_definition"
>
<cache usage="read-only"/>

<composite-id name="comp_id" class="com.tradeentity.TeDefinitionPK">
<key-property
name="contract"
column="contract"
type="java.lang.String"
length="10"
/>
<key-property
name="contractTyp"
column="contract_typ"
type="java.lang.String"
length="1"
/>
<key-property
name="optionType"
column="option_type"
type="java.lang.String"
length="1"
/>
<key-property
name="deliveryDis"
column="delivery_dis"
type="java.lang.String"
length="6"
/>
<key-property
name="strikeDispl"
column="strike_displ"
type="java.lang.String"
length="12"
/>
<key-property
name="versionNo"
column="version_no"
type="java.lang.Short"
length="6"
/>
</composite-id>
<property
name="deliveryKey"
type="int"
column="delivery_key"
not-null="true"
length="11"
/>
<property
name="seriesKey"
type="int"
column="series_key"
not-null="true"
length="11"
/>
<many-to-one name="teDate"
class="com.tradeentity.TeDate"
column="delivery_key"
insert="false"
update="false"
not-null="true"
unique="true" />

<one-to-one name="teSize"
class="com.tradeentity.TeSize">
<formula>series_key</formula>
<formula>'C'</formula>
</one-to-one>

<class
name="com.tradeentity.TeDate"
table="te_date"
>
<cache usage="read-only"/>

<id
name="deliveryKey"
type="java.lang.Integer"
column="delivery_key"
>
<generator class="assigned" />
</id>

<class
name="com.tradeentity.TeSize"
table="te_size"
>
<cache usage="read-only"/>

<composite-id name="comp_id" class="com.tradeentity.TeSizePK
">
<key-property
name="seriesKey"
column="series_key"
type="java.lang.Integer"
length="11"
/>
<key-property
name="dataCategory"
column="data_category"
type="java.lang.String"
length="1"
/>
</composite-id>


Code between sessionFactory.openSession() and session.close():
session = HibernateUtil.sessionFactory().openSession();
contractList = session.createQuery("from TeDefinition Te join fetch Te.teDate join fetch Te.teSize
where Te.comp_id.contract = :contract
")
.setString("contract",contract)
.setCacheable(true)
.setCacheRegion(BeanUser)
.list();
session.close();
System.out.println("After close");
---------------------------------------------------------------------------------
At this point works fine and gets the result set.

---------------------------------------------------------------------------------


contractList = null;
session = HibernateUtil.sessionFactory.openSes
sion();
contractList = session.createQuery("from TeDefinition Te
join fetch Te.teDate join fetch Te.teSize where Te.comp_id.contract = :contract
")
.setString("contract",contract)
.setCacheable(true)
.setCacheRegion(BeanUser)
.list();
At this point the debug messages come up and the exception comes up.
session.close();
Full stack trace of any exception that occurs:

[#|2006-05-10T17:26:12.707-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.container.ejb|_ThreadID=12;|EJB5018: An exception was thrown during an ejb i
nvocation on [TeDefinitionBean]|#]

[#|2006-05-10T17:26:12.707-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.container.ejb|_ThreadID=12;|
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseConta
iner.java:2807)
at com.sun.ejb.containers.BaseContainer.checkExceptionNoTx(BaseContainer
.java:2647)
at com.sun.ejb.containers.BaseContainer.checkExceptionBeanMgTx(BaseConta
iner.java:2585)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:
2485)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:81
9)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInv
ocationHandler.java:137)
at $Proxy22.getRow(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(Reflecti
veTie.java:123)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispa
tchToServant(CorbaServerRequestDispatcherImpl.java:648)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispa
tch(CorbaServerRequestDispatcherImpl.java:192)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest
Request(CorbaMessageMediatorImpl.java:1709)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest
(CorbaMessageMediatorImpl.java:1569)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(C
orbaMessageMediatorImpl.java:951)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.call
back(RequestMessage_1_2.java:181)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest
(CorbaMessageMediatorImpl.java:721)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatc
h(SocketOrChannelConnectionImpl.java:473)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.doWork(
SocketOrChannelConnectionImpl.java:1262)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.
run(ThreadPoolImpl.java:409)
Caused by: java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntity
Tuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(Ab
stractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessa
ry(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultL
oadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEv
entListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:838)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
at org.hibernate.type.TypeFactory.assemble(TypeFactory.java:398)
at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:96)
at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:82)
at org.hibernate.event.def.DefaultLoadEventListener.assembleCacheEntry(D
efaultLoadEventListener.java:520)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromSecondLevelC
ache(DefaultLoadEventListener.java:474)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEv
entListener.java:328)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEven
tListener.java:123)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultL
oadEventListener.java:177)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEv
entListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:838)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
at org.hibernate.cache.StandardQueryCache.get(StandardQueryCache.java:12
1)
at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2087)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2051)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImp
l.java:874)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java
:146)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.tradeentity.TeDefinitionBean.getRow(TeDefinitionB
ean.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivil
eged(EJBSecurityManager.java:950)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:158
)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInv
ocationHandler.java:128)
... 16 more
|#]

Name and version of the database you are using:
Ingres 2.6
The generated SQL (show_sql=true):
Select col1,-----------
from te_definition tedefiniti0_ inner join te_date tedate1_
on tedefiniti0_.delivery_key=tedate1_.delivery_key
inner join te_size tesize2_ on tedefiniti0_.series_key=tesize2_.series_key and 'C'=tesize2_.data_category
where (tedefiniti0_.contract=? ); parameters: ; named parameters:
Debug level Hibernate log excerpt:

[#|2006-05-10T17:26:12.666-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,665 DEBUG StandardQueryCache:147 - Checkin
g query spaces for up-to-dateness: [te_size, te_definition, te_date]
|#]

[#|2006-05-10T17:26:12.669-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,668 DEBUG EhCache:104 - key: te_size
|#]

[#|2006-05-10T17:26:12.671-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,670 DEBUG MemoryStore:204 - octts1.org.hib
ernate.cache.UpdateTimestampsCacheCache: MemoryStore miss for te_size
|#]

[#|2006-05-10T17:26:12.672-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,671 DEBUG Cache:370 - octts1.org.hibernate
.cache.UpdateTimestampsCache cache - Miss
|#]

[#|2006-05-10T17:26:12.673-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,672 DEBUG EhCache:113 - Element for te_siz
e is null
|#]

[#|2006-05-10T17:26:12.673-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,673 DEBUG EhCache:104 - key: te_definition
|#]

[#|2006-05-10T17:26:12.674-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,674 DEBUG MemoryStore:204 - octts1.org.hib
ernate.cache.UpdateTimestampsCacheCache: MemoryStore miss for te_definition
|#]

[#|2006-05-10T17:26:12.675-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,675 DEBUG Cache:370 - octts1.org.hibernate
.cache.UpdateTimestampsCache cache - Miss
|#]

[#|2006-05-10T17:26:12.676-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,676 DEBUG EhCache:113 - Element for te_def
inition is null
|#]

[#|2006-05-10T17:26:12.677-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,677 DEBUG EhCache:104 - key: te_date
|#]

[#|2006-05-10T17:26:12.678-0500|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=12;|17:26:12,678 DEBUG MemoryStore:204 - octts1.org.hib
ernate.cache.UpdateTimestampsCacheCache: MemoryStore miss for te_date


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 4:25 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
Any ideas please? Is this a bug in hibernate?


Top
 Profile  
 
 Post subject: did u got this problem solved
PostPosted: Tue Sep 19, 2006 1:29 pm 
Newbie

Joined: Fri Sep 01, 2006 10:08 pm
Posts: 4
Location: Mass
HI
Did you got this problem solved???

I am having the same problem have an object with composite id which cant be assembled back from Ehcahce

Thanks
Rahul


Top
 Profile  
 
 Post subject: found the solution
PostPosted: Wed Dec 13, 2006 2:58 pm 
Newbie

Joined: Fri Sep 01, 2006 10:08 pm
Posts: 4
Location: Mass
Wrap the query in a procedure and in the maping use the option as <Load-query>procedure name</load-query>
Access the object using get(ID) lets say ID has three parts a,b,c
So if ID is composite even it calls the procedure with
proc(a,b,c)

Hope this helps

Gets first looks the object in cache and then if it doesnt find there it looks in database


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.