| Author |
Message |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/06/2012 23:42:21
|
girish_k
journeyman
Joined: 06/06/2012 04:06:11
Messages: 13
Offline
|
I am getting org.hibernate.TransientObjectException
I activated EhCache and
running Sample project for simple entity Country1(id,name,code)
StackTrace:
Hibernate: select this_.cn_id as cn1_1_0_, this_.cn_code as cn2_1_0_, this_.cn_name as cn3_1_0_ from COUNTRY1 this_
Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Country1
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
at org.hibernate.type.ManyToOneType.disassemble(ManyToOneType.java:163)
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:80)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2194)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2138)
at org.hibernate.loader.Loader.list(Loader.java:2096)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at com.wakaleo.articles.caching.dao.CountryDAO.getCountries(CountryDAO.java:32)
at com.wakaleo.articles.caching.dao.CountryDAOTest.testGetCountries(CountryDAOTest.java:35)
at com.wakaleo.articles.caching.dao.CountryDAOTest.main(CountryDAOTest.java:91)
Java Result: 1
Code:
List resultList = null;
resultList = SessionManager.currentSession().createCriteria("Country1").setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP).setCacheable(true).list();
return resultList;
Please Reply solution
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/08/2012 06:39:22
|
alexsnaps
consul
Joined: 06/19/2009 09:06:00
Messages: 464
Online
|
So you mean making it non-cacheable solves the issue ?
|
Alex Snaps (Terracotta engineer) |
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/11/2012 04:46:36
|
girish_k
journeyman
Joined: 06/06/2012 04:06:11
Messages: 13
Offline
|
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.setCacheable(true)
the above combination giving issue.
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/11/2012 05:51:38
|
alexsnaps
consul
Joined: 06/19/2009 09:06:00
Messages: 464
Online
|
Looking closer at the stacktrace, it seems you have an unsaved entity in ... I had expected the params used on that query. Don't know what version of hibernate that is, so can't match the stacktrace for sure. Anyways, but it looks like it happens when disassembling the actual result. Now, if I read this right, the results won't be actual entities, they can't be disassembled to their PK... is this right ? As I see it this is an Hibernate (usage?) issue though... One question that comes to my mind is "are such results even cacheable ?"
|
Alex Snaps (Terracotta engineer) |
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/13/2012 22:43:40
|
girish_k
journeyman
Joined: 06/06/2012 04:06:11
Messages: 13
Offline
|
Well ... this entity(Country) is independent so no FK associated with it
Hibernate ver:3.2.5ga
Still not clear about :
Unsaved ? disassemble ?
why hibernate is handling queryCache , if EhCache is already configured?
|
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/14/2012 05:55:55
|
alexsnaps
consul
Joined: 06/19/2009 09:06:00
Messages: 464
Online
|
Hibernate _is_ the client for ehcache. Ehcache knows nothing abou Hibernate, but for the glue code (as the cache is abstracted in Hibernate).
Is that message from Hibernate clear to you:
Code:
TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: Country1
That's why I referrer to unsaved entity : transient.
As for disassemble, that's how Hibernate stores your entities in the Cache, it doesn't store the instances themselves...
|
Alex Snaps (Terracotta engineer) |
|
|
 |
![[Post New]](/forums/templates/default/images/icon_minipost_new.gif) 06/19/2012 21:30:18
|
girish_k
journeyman
Joined: 06/06/2012 04:06:11
Messages: 13
Offline
|
Still debugging with the source code
and observed that hibernate throws exception before putting it in cache
this time with following code :
Criteria fetchCriteria = SessionManager.getSession(EntityMode.MAP)
.createCriteria("Country1")
.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
.setCacheable(true);
fetchCriteria.add(Restrictions.ilike("name", (Object) "B%"));
resultList = fetchCriteria
.setFirstResult(0)
.list();
And works if setResultTransformer is commented.
|
|
|
 |
|
|