-->
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: Unable to execute sql query in interceptor
PostPosted: Fri Oct 26, 2007 7:58 am 
Newbie

Joined: Fri Oct 27, 2006 3:02 am
Posts: 4
I am trying to execute sql select query in interceptor method go get some meta data used to generate audits log.
I am intercepting insert/update operation on entities, and i am trying to get meta data(executin sql query from meta data tables) for the related entities to generate log. I am getting exception while execute a query .

I have 2 transactional entities Entity1 and Entity2. Entity1 has one to may association with Entity2. A new instance of Entity1 is created and added a new instance of Entity2 to its set and i am saving Entity1.

In interceptor onSave for Entity1 I need to log some audit information for this transaction based on what changed in Entity1, to achieve this i need to read a table to meta data required to log audits. I am trying to execute a sql query to get the data. I am getting the following exeception which i posted at the end.

But when i replace sql query with session.get(objce, id) it works. How different this get method works?

hibernate version 3.2.4
mappings

<hibernate-mapping>
<class name="com.fmrco.insight.MavenTest.hibernate.entities.Entity1" table="ENTITY1" schema="TECDATA">
<id name="id" type="java.lang.Double">
<column name="ID" precision="15" scale="0" />
<generator class="assigned" />
</id>
<property name="name" type="java.lang.String">
<column name="NAME" not-null="true" />
</property>
<property name="msg" type="java.lang.String">
<column name="MSG" not-null="true" />
</property>
<set name="entity2s" inverse="true" cascade="all">
<key>
<column name="PARENT_ID" precision="15" scale="0" />
</key>
<one-to-many class="com.fmrco.insight.MavenTest.hibernate.entities.Entity2" />
</set>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="com.fmrco.insight.MavenTest.hibernate.entities.Entity2" table="ENTITY2" schema="TECDATA">
<id name="id" type="java.lang.Double">
<column name="ID" precision="15" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="entity1" class="com.fmrco.insight.MavenTest.hibernate.entities.Entity1" fetch="select">
<column name="PARENT_ID" precision="15" scale="0" />
</many-to-one>
<property name="name" type="java.lang.String">
<column name="NAME" not-null="true" />
</property>
<property name="childmsg" type="java.lang.String">
<column name="CHILDMSG" />
</property>
</class>
</hibernate-mapping>

my code

Entity1 e = new Entity1 ();
e.setMsg("i am parent");
e.setName("parent");
e.setId(8.0);
Entity2 e2 = new Entity2 ();
e2.setId(8.0);
e2.setChildmsg("I am child");
e2.setName("child");
e.addEntity2s(e2); // add to collection and set Entity1 refernce in Entity2
new Entity1DAO ().save(e);


I am using timesten in memory database (7.0.2). Any help to solve this problem/ explain why hibernate behave differently (query / get method) will be helpfull.


thread "main" java.lang.IllegalStateException: persistence context reported no row snapshot for [com.fmrco.insight.MavenTest.hibernate.entities.Entity2#8.0]
at org.hibernate.engine.StatefulPersistenceContext.getCachedDatabaseSnapshot(StatefulPersistenceContext.java:300)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getDatabaseSnapshot(DefaultFlushEntityEventListener.java:516)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:477)
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:197)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.fmrco.insight.MavenTest.hibernate.entities.AuditableEntityDAO.findByProperty(AuditableEntityDAO.java:86)
at com.fmrco.insight.MavenTest.hibernate.entities.AuditableEntityDAO.findByApplication(AuditableEntityDAO.java:94)
at com.fmrco.insight.MavenTest.hibernate.entities.HibernateInterceptor.onSave(HibernateInterceptor.java:104)
at org.hibernate.event.def.AbstractSaveEventListener.substituteValuesIfNecessary(AbstractSaveEventListener.java:394)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:270)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:218)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.fmrco.insight.MavenTest.hibernate.entities.AuditableEntityDAO.findByProperty(AuditableEntityDAO.java:86)
at com.fmrco.insight.MavenTest.hibernate.entities.AuditableEntityDAO.findByApplication(AuditableEntityDAO.java:94)
at com.fmrco.insight.MavenTest.hibernate.entities.HibernateInterceptor.onSave(HibernateInterceptor.java:104)
at org.hibernate.event.def.AbstractSaveEventListener.substituteValuesIfNecessary(AbstractSaveEventListener.java:394)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:270)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at com.fmrco.insight.MavenTest.hibernate.entities.Entity1DAO.save(Entity1DAO.java:30)
at com.fmrco.insight.MavenTest.hibernate.entities.test.TestHibernate.main(TestHibernate.java:22)


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.