-->
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: Query is causing an extraneous UPDATE on commit.
PostPosted: Tue Sep 26, 2006 2:10 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 3:19 pm
Posts: 34
I'm running into the problem described here, http://forum.springframework.org/showthread.php?t=9702. And indeed, their session.clear() suggestion does work around the issue.

Why is this occuring though? Logging indicates this is the first time the session is opened (I use the HibernateService defined in the Hibernate in Action book). Nothing could have "dirtied" the objects at this point. Why is my query causing it to execute an UPDATE? And why is the update failing?

Hibernate version:
2.1

Mapping documents:
<class name="DashboardSummary" table="DASH_BOARD_SUMMARY">
<id name="id" column="ID">
<generator class="assigned" />
</id>
<set name="serviceGroupSummary" lazy="true" inverse="true" >
<key column="SUMMARY_ID"/>
<one-to-many class="ServiceGroupSummary"/>
</set>
</class>

<class name="ServiceGroupSummary" table="SERVICE_GROUP_DASH_BOARD" >
<id name="id" column="ID">
<generator class="assigned" />
</id>
<many-to-one name="dashboardSummary" class="DashboardSummary" column="SUMMARY_ID" />
</class>

Code between sessionFactory.openSession() and session.close():
try {
LOG.info("getServiceGroupSummary enter");
_hibSvc.beginTransaction();
ServiceGroupActivityQuery query = new ServiceGroupActivityQuery(criteria, _hibSvc);
result = query.createQuery().list();
_hibSvc.commitTransaction();
return result;
} catch (HibernateException e) {
throw new NableServiceException( e );
} finally {
_hibSvc.endSession();
}
}


Full stack trace of any exception that occurs:
2006-09-26 10:34:10,407 [loadSDVDashboardBackgroundThread] ERROR JDBCExceptionReporter Could not execute JDBC batch update

java.sql.BatchUpdateException: ORA-01407: cannot update ("MC"."SERVICE_GROUP_DASH_BOARD"."SUMMARY_ID") to NULL
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.ncube.nable.platform.hibernate.HibernateService.commitTransaction(HibernateService.java:246)
at com.ncube.nable.app.mc.sdv.activity.ServiceGroupActivityService.getServiceGroupSummary(ServiceGroupActivityService.java:115)
at com.ncube.nable.app.mc.sdv.gui.action.DashboardAction.loadServiceGroups(DashboardAction.java:182)
at com.ncube.nable.app.mc.sdv.gui.action.DashboardAction.execute(DashboardAction.java:93)
at com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor$1.run(ExecuteAndWaitInterceptor.java:101)
at java.lang.Thread.run(Thread.java:595)

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

The generated SQL (show_sql=true):
2006-09-26 10:34:09,557 [loadSDVDashboardBackgroundThread] INFO hibernate Starting new database transaction in this thread.
2006-09-26 10:34:09,557 [loadSDVDashboardBackgroundThread] DEBUG hibernate Opening new Session for this thread.
2006-09-26 10:34:10,094 [loadSDVDashboardBackgroundThread] DEBUG SQL select servicegro0_.ID as ID, servicegro0_.SERVICE_GROUP as SERVICE_2_, servicegro0_.USED_BANDWIDTH as USED_BAN3_, servicegro0_.TOTAL_BANDWIDTH as TOTAL_BA4_, servicegro0_.ACTIVE_CHANNELS as ACTIVE_C5_, servicegro0_.TOTAL_CHANNELS as TOTAL_CH6_, servicegro0_.ACTIVE_SESSIONS as ACTIVE_S7_, servicegro0_.SUMMARY_ID as SUMMARY_ID from MC.SERVICE_GROUP_DASH_BOARD servicegro0_

2006-09-26 10:34:10,360 [loadSDVDashboardBackgroundThread] DEBUG SQL select dashboards0_.ID as ID0_, dashboards0_.CREATED_AT as CREATED_AT0_, dashboards0_.VMID as VMID0_ from MC.DASH_BOARD_SUMMARY dashboards0_ where dashboards0_.ID=?

2006-09-26 10:34:10,375 [loadSDVDashboardBackgroundThread] DEBUG SQL update MC.SERVICE_GROUP_DASH_BOARD set SERVICE_GROUP=?, USED_BANDWIDTH=?, TOTAL_BANDWIDTH=?, ACTIVE_CHANNELS=?, TOTAL_CHANNELS=?, ACTIVE_SESSIONS=?, SUMMARY_ID=? where ID=?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 2:32 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Are you sure that the primary key is at the "unassigned value" so that Hibernate doesnt think that its probably an update ?
A good way to see why this is happening is to turn on the log level to debug and see the number of updates/inserts that are happening. That should give u some idea as to why the update is fired


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 3:33 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 3:19 pm
Posts: 34
rajasaur wrote:
Are you sure that the primary key is at the "unassigned value" so that Hibernate doesnt think that its probably an update ?
A good way to see why this is happening is to turn on the log level to debug and see the number of updates/inserts that are happening. That should give u some idea as to why the update is fired


The logging is on (see above SQL). I can see the SELECT for the query followed by an UPDATE when the transaction is committed.

I'm not sure about the unassigned value. I'll have to look.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 6:19 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 3:19 pm
Posts: 34
It's not the value of the keys. They have a valid value. In fact, the assigned shouldn't even matter in the tests I'm running. It's a query so Hibernate is apparently loading the objects then deciding they don't have the SUMMARY_ID set for some reason. But the values in the database are all non-zero and match up correctly for the various foreign key relationships.

I did add a <version> and update="false" and insert="false" and the problem went away. Well, covered it up since I've basically told hibernate to never try to update that relationship.

I'm not sure why it was trying to update it in the first place though given I'm only doing a query. That's what's really bothering me. I don't see anything in the mapping that looks like it should cause that kind of behavior.


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.