-->
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: Strange behavior: the same query twice in the same session
PostPosted: Tue Aug 10, 2004 3:20 pm 
Beginner
Beginner

Joined: Mon May 03, 2004 1:25 pm
Posts: 31
I have two named queries that run iteratively within the same session, query a runs then b then a again, etc. The first time through both run fine, but when query a tries to run again (with new where clause variables), it throws a "Can't write to a readonly object" exception. If I clear the session, it runs fine. Why would it try to update the


Hibernate version:2.1.6

Mapping documents:
<class name="PopulationElement" table="wtg_population" >
<jcs-cache usage="read-only"/>
<id name="id" type="long" column="POPULATION_ID">
<generator class="assigned"/>
</id>
<property name="serviceId" column="SERVICE_CODE"/>
<property name="surveyId" column="SURVEY_CODE"/>
<property name="sampleGeoGnmbr" column="SMPL_GEO_GNMBR"/>
<property name="value" column="POP_VALUE" type="long"/>
<property name="ethnicCode" column="ETHNIC_CODE"/>
<property name="gender" column="GENDER_CODE"/>
<property name="startAge" column="START_AGE"/>
<property name="endAge" column="END_AGE"/>
</class>
<class name="Target" table="SMPL_GEO_TRGTS">
<jcs-cache usage="read-only"/>
<composite-id>
<key-property name="surveyId" column="SRVY_ID"/>
<key-property name="sampleGeoGnmbr" column="SMPL_GEO_GNMBR"/>
</composite-id>
<property name="target" column="INTAB_TRGT_CNT"/>
</class>
<query name="com.arbitron.geodemo.Populations"><![CDATA[Select distinct pe
from PopulationElement pe
where pe.serviceId = :serviceId
and pe.surveyId = :surveyId
and pe.sampleGeoGnmbr in (:sampleGeoGnmbr)
]]>
</query>
<query name="com.arbitron.geodemo.Targets"><![CDATA[Select distinct tg
from Target tg
where tg.surveyId = :surveyId
and tg.sampleGeoGnmbr in (:sampleGeoGnmbr)
]]>
</query>


Code between sessionFactory.openSession() and session.close():
Query q = sess.getNamedQuery("com.arbitron.geodemo.Populations");
q.setString("serviceId", "RADIO");
q.setString("surveyId", "FA03");
q.setParameterList("sampleGeoGnmbr", sampleGeos, new net.sf.hibernate.type.LongType());
List qlist= q.list();

Different method:
Query targetQuery = sess.getNamedQuery("com.arbitron.geodemo.Targets");
targetQuery.setString("surveyId", "FA03");
targetQuery.setParameterList("sampleGeoGnmbr",cId,new net.sf.hibernate.type.LongType());
targetIter = targetQuery.list()


Full stack trace of any exception that occurs:
11526 ERROR [AWT-EventQueue-0] () - Application attempted to edit read only item: 560166
java.lang.UnsupportedOperationException: Can't write to a readonly object
at net.sf.hibernate.cache.ReadOnlyCache.lock(ReadOnlyCache.java:36)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:50)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1811)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1568)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.arbitron.geodemo.PopulationHelper.<init>(PopulationHelper.java:68)
at com.arbitron.currency.weight.diary.ModelSetFactory.getCountyPopHelper(ModelSetFactory.java:805)
at com.arbitron.currency.weight.diary.ModelSetFactory.createNonEthnicModel(ModelSetFactory.java:698)
at com.arbitron.currency.weight.diary.ModelSetFactory.createModels(ModelSetFactory.java:638)
at com.arbitron.currency.weight.diary.ModelSetFactory.createModelSet(ModelSetFactory.java:481)
at com.arbitron.currency.weight.diary.ModelSetFactory.<init>(ModelSetFactory.java:447)
at com.arbitron.currency.weighting.ui.WeightingRunUI.getModelSet(WeightingRunUI.java:195)
at com.arbitron.currency.weighting.ui.WeightingRunUI.determine(WeightingRunUI.java:287)
at com.arbitron.currency.weighting.ui.WeightingRunUI.actionPerformed(WeightingRunUI.java:251)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException
at com.arbitron.geodemo.PopulationHelper.<init>(PopulationHelper.java:74)
at com.arbitron.currency.weight.diary.ModelSetFactory.getCountyPopHelper(ModelSetFactory.java:805)
at com.arbitron.currency.weight.diary.ModelSetFactory.createNonEthnicModel(ModelSetFactory.java:698)
at com.arbitron.currency.weight.diary.ModelSetFactory.createModels(ModelSetFactory.java:638)
at com.arbitron.currency.weight.diary.ModelSetFactory.createModelSet(ModelSetFactory.java:481)
at com.arbitron.currency.weight.diary.ModelSetFactory.<init>(ModelSetFactory.java:447)
at com.arbitron.currency.weighting.ui.WeightingRunUI.getModelSet(WeightingRunUI.java:195)
at com.arbitron.currency.weighting.ui.WeightingRunUI.determine(WeightingRunUI.java:287)
at com.arbitron.currency.weighting.ui.WeightingRunUI.actionPerformed(WeightingRunUI.java:251)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


Name and version of the database you are using:Oracle 9i

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 5:07 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Have you altered the data in one of the PopulationElement objects that has been pulled out in one of the queries?

It looks like the session is auto-flushing the data in the session, before it re-runs the query, and has found that one of your objects has data that has changed. The session is trying to update the object, but since you've declared that the objects are to be treated as read-only in the cache, it's falling over as that isn't allowed.


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