Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Help appreciated. I'm getting transaction deadlocked on a flush() call (see below stack trace). The sessions are retrieved from ThreadLocal. The code piece that seems to cause this problem is:
if (dataManager.currentSession() == null)
{
dataManager.currentSession(true); //create a seesion
}
else
{
dataManager.currentSession().flush();
}
aLun = deviceManager.getLunByIdentifier(idStr);
dataManager.currentSession() looks like:
static public Session currentSession(boolean create) throws HibernateException {
org.hibernate.Session session = null;
session = (Session)threadSession.get();
// Open a new Session, if this Thread has none yet
if ((session == null) && create) {
session = sessionFactory.openSession(new DataObjectInterceptor());
threadSession.set(session);
}
return session;
}
Hibernate version:
3.x
Mapping documents:
<hibernate-mapping default-lazy="false">
<class name="com.crosswalk.knowledgebase.device.Lun" table="cwsm_lun">
<meta attribute="export-id">identifier</meta>
<!-- Use Long id with HILO key generation -->
<id name="id" type="long" unsaved-value="null" >
<column name="id" sql-type="long" not-null="true"/>
<generator class="hilo">
<param name="table">cwsm_unique_key</param>
<param name="column">next_value</param>
<param name="max_lo">1000</param>
</generator>
</id>
<property name="state" type="integer">
<meta attribute="dataType">list</meta>
<meta attribute="dataType.domain">network_object_states</meta>
<meta attribute="exportable">false</meta>
<meta attribute="label">State</meta>
<column name="state" not-null="true"/>
</property>
<property name="stateDate" type="timestamp">
<meta attribute="exportable">false</meta>
<column name="state_date" not-null="true"/>
</property>
<property name="identifier" type="string">
<meta attribute="exportable" inherit="false">false</meta>
<column name="identifier" length="255" not-null="true"/>
</property>
<property name="lunType" type="integer">
<meta attribute="dataType">list</meta>
<meta attribute="dataType.domain">lun_types</meta>
<meta attribute="label">LUN Type</meta>
<column name="lun_type" not-null="true"/>
</property>
<property name="size" type="long">
<meta attribute="label">Size</meta>
<column name="size" not-null="false"/>
</property>
<property name="lunNumber" type="string">
<meta attribute="label">Number</meta>
<column name="lun_number" length="64" not-null="false"/>
</property>
<property name="arrayVolumeName" type="string">
<meta attribute="label">Array Volume Name</meta>
<column name="array_volume_name" length="128" not-null="false"/>
</property>
<property name="raidLevel" type="string">
<meta attribute="label">RAID Level</meta>
<column name="raid_level" length="32" not-null="false"/>
</property>
<property name="createdOn" type="timestamp">
<meta attribute="exportable">false</meta>
<column name="created_on" not-null="true"/>
</property>
<property name="modifiedOn" type="timestamp">
<meta attribute="exportable">false</meta>
<column name="modified_on" not-null="false"/>
</property>
<set name="targetPorts" inverse="true" lazy="false" cascade="save-update" table="cwsm_lun_target_port">
<meta attribute="label">Target Ports</meta>
<meta attribute="as-references">true</meta>
<key column="lun_id"/>
<many-to-many class="com.crosswalk.knowledgebase.device.Port" column="port_id"/>
</set>
<set name="initiatorPorts" inverse="true" lazy="true" cascade="save-update" table="cwsm_lun_initiator_port">
<meta attribute="label">Initiator Ports</meta>
<meta attribute="as-references">true</meta>
<key column="lun_id"/>
<many-to-many class="com.crosswalk.knowledgebase.device.Port" column="port_id"/>
</set>
<many-to-one name="storagePool" class="com.crosswalk.knowledgebase.device.StoragePool" column="storage_pool_id" not-null="true" cascade="none">
<meta attribute="label">Storage Pool</meta>
</many-to-one>
<set name="storageExtents" inverse="false" lazy="true" cascade="none">
<meta attribute="exportable">false</meta>
<key column="lun_id"/>
<one-to-many class="com.crosswalk.knowledgebase.device.StorageExtent"/>
</set>
<one-to-one name="attachedStorage" property-ref="lun" class="com.crosswalk.knowledgebase.device.PhysicalVolume" cascade="all" lazy="true"/>
</class>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
org.hibernate.util.JDBCExceptionReporter 2005-06-22 09:01:05,393 -- WARN -- SQL Error: 0, SQLState: null
org.hibernate.util.JDBCExceptionReporter 2005-06-22 09:01:05,657 -- ERROR -- Transaction (Process ID 51) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
org.hibernate.event.def.AbstractFlushingEventListener 2005-06-22 09:01:05,657 -- ERROR -- 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:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678)
at com.crosswalk.knowledgebase.data.HibernateSession.flush(HibernateSession.java:55)
at com.crosswalk.knowledgebase.cim.Cim2LunUtil.getLunFromKbByIdentifier(Cim2LunUtil.java:521)
at com.crosswalk.knowledgebase.cim.Cim2LunUtil.cimInstance2Lun(Cim2LunUtil.java:370)
at com.crosswalk.knowledgebase.cim.Cim2StoragePoolUtil.cimInstance2StoragePool(Cim2StoragePoolUtil.java:332)
at com.crosswalk.knowledgebase.cim.Cim2ArrayUtil.discoverArray(Cim2ArrayUtil.java:629)
at com.crosswalk.knowledgebase.cim.Cim2ArrayUtil.discoverArrays(Cim2ArrayUtil.java:199)
at com.crosswalk.knowledgebase.cim.CimDataManager.discoverArrays(CimDataManager.java:546)
at com.crosswalk.knowledgebase.cim.CimDataManager.persistArrayData(CimDataManager.java:488)
at com.crosswalk.knowledgebase.cim.ArrayDiscoverySchedule.discover(ArrayDiscoverySchedule.java:61)
at com.crosswalk.knowledgebase.cim.ArrayDiscoverySchedule.execute(ArrayDiscoverySchedule.java:54)
at com.crosswalk.knowledgebase.util.ScheduleTask.run(ScheduleTask.java:29)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: Transaction (Process ID 51) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
at net.sourceforge.jtds.jdbc.TdsStatement.executeBatch(TdsStatement.java:933)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
... 18 more
Name and version of the database you are using:
MS SQL server 8.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: