<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Tahoma">Hello All,<br>
<br>
I'm in need of some insight on a hibernate problem.<br>
<br>
A little about the environment<br>
<br>
- hibernate 3.2 CR2<br>
- Spring 1.2.8<br>
<br>
some background...<br>
<br>
We have some logic which performs several operations on the db in a
fairly random sequence... one of the operations is an SQL insert via
hibernate<br>
<br>
</font></font>
<pre> <font color="#ff0000"><strong>try</strong></font> {
session = openSession();
<font color="#ff0000"><strong>if</strong></font> (draftAction.isNew()) {
session.save(draftAction);
}
session.flush();
draftAction.setNew(<font color="#5f9ea0">false</font>);
<font color="#ff0000"><strong>return</strong></font> draftAction;
} <font color="#ff0000"><strong>catch</strong></font> (<font
color="#4682b4">HibernateException</font> he) {
<font color="#ff0000"><strong>throw</strong></font> <font
color="#ff0000"><strong>new</strong></font> <font color="#4682b4">SystemException</font>(he);
} <font color="#ff0000"><strong>finally</strong></font> {
}
</pre>
<font size="-1"><font face="Tahoma"><br>
Now, since the sequence is random, we are expecting an exception to be
thrown, because due to the behaviour of our business logic, the object
we're trying ti insert may already exist in the db. So we are <br>
anticipating it.<br>
<br>
Here is the info log in the catch block wrapping the dao insert call:<br>
</font></font>
<pre>22:19:41,634 <font color="#4682b4">INFO</font> [<font
color="#4682b4">DraftUtil</font>:581] com.sc.<font color="#4682b4">ScApplicationException</font>: com.liferay.portal.<font
color="#4682b4">SystemException</font>: org.hibernate.exception.<font
color="#4682b4">ConstraintViolationException</font>: <font
color="#4682b4">Could</font> not execute <font color="#4682b4">JDBC</font> batch update
com.liferay.portal.<font color="#4682b4">SystemException</font>: com.sc.<font
color="#4682b4">ScApplicationException</font>: com.liferay.portal.<font
color="#4682b4">SystemException</font>: org.hibernate.exception.<font
color="#4682b4">ConstraintViolationException</font>: <font
color="#4682b4">Could</font> not execute <font color="#4682b4">JDBC</font> batch update
at com.sc.portlet.draft.service.spring.<font color="#4682b4">DraftActionLocalServiceUtil</font>.addDraftAction(<font
color="#4682b4">DraftActionLocalServiceUtil</font>.java:14)
at com.sc.portlet.draft.util.<font color="#4682b4">DraftUtil</font>.doAutoDraft(<font
color="#4682b4">DraftUtil</font>.java:570)
at com.sc.portlet.draft.util.<font color="#4682b4">DraftUtil</font>.autoDraftRound(<font
color="#4682b4">DraftUtil</font>.java:495)
at com.sc.portlet.fantasyteam.mlb.draft.action.<font
color="#4682b4">JSONDraftedDataAction</font>.getJSON</pre>
<br>
<br>
<font size="-1"><font face="Tahoma">So, at a high level, imagine that
there are 1000 choices to pick from, only one choice can be made,
choices are made randomly, everyone's choice must be unique among the
1000, and there are 12 people making a choice in a random order, one
after another. in a loop...<br>
<br>
So the insert is both the selection action and the determination of
whether the choice is already used up (when the exception is thrown,
try again)...<br>
<br>
<br>
The problem: randomly during execution (but very frequently) we are
getting threads which become deadlocked while performing this operation
and never return, and eventually all thread in the system are used up
and the server become unresponsive.<br>
<br>
<br>
Here is the hbm for one object:<br>
<br>
<br>
</font></font>
<pre>        <<font color="#ff0000"><strong>class</strong></font> name=<font
color="#008b00">"com.sc.portlet.draft.model.<font color="#4682b4">DraftAction</font>" table="<font
color="#4682b4">DraftAction</font>"</font>>
                <cache usage=<font color="#008b00">"read-write"</font> />
                <composite-id name=<font color="#008b00">"primaryKey" <font
color="#ff0000"><strong>class</strong></font>="com.sc.portlet.draft.service.persistence.<font
color="#4682b4">DraftActionPK</font>"</font>>
                        <key-property name=<font color="#008b00">"draftId"</font> />
                        <key-property name=<font color="#008b00">"fantasyTeamId"</font> />
                        <key-property name=<font color="#008b00">"round"</font> />
                </composite-id>
                <property name=<font color="#008b00">"action" type="com.liferay.util.dao.hibernate.<font
color="#4682b4">StringType</font>"</font> />
                <property name=<font color="#008b00">"range" type="com.liferay.util.dao.hibernate.<font
color="#4682b4">StringType</font>"</font> />
                <property name=<font color="#008b00">"playerId" type="com.liferay.util.dao.hibernate.<font
color="#4682b4">StringType</font>"</font> />
                <property name=<font color="#008b00">"createDate"</font> />
        </<font color="#ff0000"><strong>class</strong></font>>
</pre>
<br>
<font size="-1"><font face="Tahoma">Here is the Spring config for the
dao:<br>
<br>
</font></font>
<pre>        <bean id=<font color="#008b00">"com.sc.portlet.draft.service.spring.<font
color="#4682b4">DraftActionLocalService</font>.professional" <font
color="#ff0000"><strong>class</strong></font>="com.sc.portlet.draft.service.impl.<font
color="#4682b4">DraftActionLocalServiceImpl</font>" lazy-init="<font
color="#5f9ea0">true</font>"</font> />
        <bean id=<font color="#008b00">"com.sc.portlet.draft.service.spring.<font
color="#4682b4">DraftActionLocalService</font>.transaction" <font
color="#ff0000"><strong>class</strong></font>="org.springframework.transaction.interceptor.<font
color="#4682b4">TransactionProxyFactoryBean</font>" lazy-init="<font
color="#5f9ea0">true</font>"</font>>
                <property name=<font color="#008b00">"transactionManager"</font>>
                        <ref bean=<font color="#008b00">"liferayTransactionManager"</font> />
                </property>
                <property name=<font color="#008b00">"target"</font>>
                        <ref bean=<font color="#008b00">"com.sc.portlet.draft.service.spring.<font
color="#4682b4">DraftActionLocalService</font>.professional"</font> />
                </property>
                <property name=<font color="#008b00">"transactionAttributes"</font>>
                        <props>
                                <prop key=<font color="#008b00">"*"</font>><font
color="#4682b4">PROPAGATION_REQUIRED</font></prop>
                        </props>
                </property>
        </bean>
        <bean id=<font color="#008b00">"com.sc.portlet.draft.service.spring.<font
color="#4682b4">DraftActionLocalServiceFactory</font>" <font
color="#ff0000"><strong>class</strong></font>="com.sc.portlet.draft.service.spring.<font
color="#4682b4">DraftActionLocalServiceFactory</font>" lazy-init="<font
color="#5f9ea0">true</font>"</font>>
                <property name=<font color="#008b00">"service"</font>>
                        <ref bean=<font color="#008b00">"com.sc.portlet.draft.service.spring.<font
color="#4682b4">DraftActionLocalService</font>.transaction"</font> />
                </property>
        </bean>
</pre>
<br>
<font size="-1"><font face="Tahoma">If anyone has any insight on why
this might occur I would be very greatful.<br>
<br>
Thank you,<br>
<br>
<br>
Raymond Auge<br>
</font></font>
</body>
</html>