-->
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: Exception on second run of one-to-one mapping
PostPosted: Mon Mar 13, 2006 3:17 pm 
Newbie

Joined: Mon Mar 13, 2006 3:02 pm
Posts: 3
Hibernate version:version 3.1.2, Jan 27, 2006


A component can have one or many children of type component, basically a tree.
A Component is associated through a one-to-one relationship to a block
I can run my test once, both component and block are persisted OK.
The second time an exception I get an exception:
Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update

Any Ideas?

Thanks in advance.

Class Block:

<class name="com.actenum.allora.vo.Block" table="BLOCK" select-before-update="true">
<id name="id" column="COMPONENT_ID" unsaved-value="null">
<generator class="foreign">
<param name="property">component</param>
</generator>
</id>
<version name="version" type="long" column="version"/>
<one-to-one name="component" class="com.actenum.allora.vo.Component" constrained="true"/>


<property name="name" type="string" length="64" />
<property name="description" type="string" length="512" />
<property name="createdBy" type="string" length="128" />
<property name="modifiedBy" type="string" length="128"/>

<component name="createDtm"
class="com.actenum.allora.vo.UtcDateTime">
<property name="milliSecs" type="long" column="create_date" />
</component>

<component name="modifiedDtm"
class="com.actenum.allora.vo.UtcDateTime">
<property name="milliSecs" type="long"
column="modified_date" />
</component>

</class>



Class Component:

<class name="com.actenum.allora.vo.Component" table="COMPONENT" select-before-update="true" where="parent_id is null">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="id" not-null="true" />
<generator class="native" />
</id>
<version name="version" type="long" column="version"/>

<property name="externalId" type="string" unique="true"/>
<property name="deleted" type="boolean" not-null="true"/>
<property name="role" type="com.actenum.allora.server.utils.RoleEnumUserType" not-null="true" length="16"/>

<one-to-one name="block" class="com.actenum.allora.vo.Block" cascade="save-update"/>

<many-to-one name="parent" class="com.actenum.allora.vo.Component">
<column name="parent_id" not-null="false" />
</many-to-one>

<list name="children" inverse="false" table="COMPONENT"
cascade="all" lazy="false">
<key column="parent_id" not-null="false" />
<index column="idx" />
<one-to-many class="com.actenum.allora.vo.Component" />
</list>

<component name="effectiveStartDtm"
class="com.actenum.allora.vo.UtcDateTime">
<property name="milliSecs" type="long"
column="effective_Start" />
</component>

<component name="effectiveEndDtm"
class="com.actenum.allora.vo.UtcDateTime">
<property name="milliSecs" type="long"
column="effective_End" />
</component>

<many-to-one name="componentType" class="com.actenum.allora.vo.ComponentType" unique="true" lazy="false">
<column name="component_type_id" not-null="true" />
</many-to-one>

<property name="name" type="string" length="64" />
<property name="description" type="string" length="512" />
<property name="createdBy" type="string" length="128" />
<property name="modifiedBy" type="string" length="128"/>




<component name="createDtm"
class="com.actenum.allora.vo.UtcDateTime">
<property name="milliSecs" type="long" column="create_date" />
</component>

<component name="modifiedDtm"
class="com.actenum.allora.vo.UtcDateTime">
<property name="milliSecs" type="long"
column="modified_date" />
</component>

</class>


Save code

try {
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
session.saveOrUpdate(vo);
tx.commit();

} catch (Exception e) {
tx.rollback();
ServiceException se = new ServiceException();
se.setWrappedException(e);
throw se;
} finally {
HibernateUtil.closeSession();
}



WARN main JDBCExceptionReporter logExceptions - SQL Error: 0, SQLState: null
ERROR main JDBCExceptionReporter logExceptions - failed batch
ERROR main AbstractFlushingEventListener performExecutions - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.actenum.allora.service.ProcessModelServiceDB.save(ProcessModelServiceDB.java:34)
at unittests.com.actenum.alloraserver.TestProcessModelServiceDB.testSaveExistingComponentBlock(TestProcessModelServiceDB.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 24 more


This is running on Hypersonic 1.8.0


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 5:00 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
I have a few questions on your problem:

1) vo - what is it and how is it created.. can you show the code.

2) when you say that the "2nd time you run it" ... what do you mean? - is it a 2nd request? is it the 2nd time within the same Session? Are you saving the Session and/or the SessionFactory between requests?

3) if you are saving Session/SessionFactory are you mindful of the caching that is going on? Are you reattaching your objects properly?

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 6:02 pm 
Newbie

Joined: Mon Mar 13, 2006 3:02 pm
Posts: 3
1)
Both Component and Block are vos (Value Objects).

public abstract class AbstractPrimaryVO extends AbstractVO
private String m_name;
private String m_description;
private long m_version;
ETC...

I have a Manager that performs the CRUD calls on the VOs:

class DBManager :
public AbstractPrimaryVO save(AbstractPrimaryVO vo) throws ServiceException {
Session session = null;
Transaction tx = null;

try {
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
session.saveOrUpdate(vo);
tx.commit();

} catch (Exception e) {
tx.rollback();
ServiceException se = new ServiceException();
se.setWrappedException(e);
throw se;
} finally {
HibernateUtil.closeSession();
}
return vo;
}

2) I have a unit test that inserts a component into the DB:

Component aComponent = getComponent(true);
Block aBlock = new Block();
aBlock.setComponent(aComponent);
aComponent.setBlock(aBlock);
DBManager.save(aComponent);

3) Not really doing anything as far as point 3) is concerned.

Thanks for your reply


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 6:19 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
There is a lot to mule over here. So from a quick smell test... I'll throw out my 2 bits:

Not sure about this, since I haven't played with the "where= in a class tag"... but that may be the issue.

"where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class".

So since you are asking hinberate to "select-before-update" to verify the state of you objects, I am wondering if when hibernate selects, it is not pulling up the correct info... and its state is out of sync.

Also check that you have the correct values for the ID's on the second attempt to save. If all is well, it will just try an update of the current objects, that changed. The "select-before-update" is to guarantee you that no one else changed the objects outside of your session scope.

Hope this helps!

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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