title: JPA ECLIPSELINK issues SELECT 1
body: <p>All,  </p>
  
  <p>Why does EL issues SELECT 1 after every exception ? Is there a way to avoid the issuing of this SELECT 1 as it is hanging/locking the table and the connection is not being released?  </p>
  
  <p>Please let me know why does this happen and is there a way to get past this?<br>
  Thanks!</p>
  
  <p>[UPDATE]<br>
  Sure, its RESOURCE_LOCAL and I use JPAEclipseCustmizer to set the connection,</p>
  
  <pre><code>&lt;persistence version="2.0" ...&gt;
  &lt;persistence-unit name="test" transaction-type="RESOURCE_LOCAL"&gt;
  ....
  &lt;properties&gt; 
  &lt;property name="eclipselink.session.customizer" value="xxx.JpaEclipseLinkSessionCustomizer" /&gt;
  &lt;/properties&gt; 
  </code></pre>
  
  <p>And the error log, if you notice, there is no trace of <strong>end unit of work commit</strong> which I believe may be tagged to the issue. And after this excpetion, the SELECT 1 is blocking other processes as I see from Database Proceeses list</p>
  
  <p>[EL Finer]: 2014-06-01 01:15:24.73--ClientSession(454114973)--Connection(1046369599)--Thread(Thread[Timer-0,10,main])--Begin batch statements
      [EL Fine]: 2014-06-01 01:15:24.731--ClientSession(454114973)--Connection(1046369599)--Thread(Thread[Timer-0,10,main])--INSERT INTO xxx (name) VALUES (?)
      [EL Fine]: 2014-06-01 01:15:24.732--ClientSession(454114973)--Connection(1046369599)--Thread(Thread[Timer-0,10,main])-- bind => [xxx]
      [EL Finer]: 2014-06-01 01:15:24.733--ClientSession(454114973)--Connection(1046369599)--Thread(Thread[Timer-0,10,main])--End Batch Statements
      [EL Fine]: 2014-06-01 01:15:24.74--ClientSession(454114973)--Thread(Thread[Timer-0,10,main])--SELECT 1
      [EL Warning]: 2014-06-01 01:15:24.744--ClientSession(454114973)--Thread(Thread[Timer-0,10,main])--Local Exception Stack: 
      Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: com.sybase.jdbc3.jdbc.SybBatchUpdateException: JZ0BE: BatchUpdateException: Error occurred while executing batch statement: Attempt to insert duplicate key row in object 'xxx' with unique index 'pk_xxx'</p>
  
  <pre><code>Error Code: 0
  at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
  at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeJDK12BatchStatement(DatabaseAccessor.java:830)
  </code></pre>
  
  <p><strong>[UPDATE 2]</strong><br>
  Looks like the problem comes down to the commit piece, when I try to insert a record into the table that already exists, it fails with the unique constraint issue. Along with that what happens is my sql is not rollback and so the chained mode is not set back to off.<br>
  I get to see the below in the db logs,  </p>
  
  <pre><code> set CHAINED on 
   DELETE FROM xx WHERE (xx = @p0) 
   commit 
   commit 
   set CHAINED off 
   SELECT xx FROM xx 
   set CHAINED on 
   INSERT INTO xx (xx) VALUES (@p0x) 
   SELECT 1  
  </code></pre>
  
  <p>If you notice the above, its clear that the set chained mode is not set back to off again and this is holding the connection to be locked (along with the SELECT 1).</p>
  
  <p>And the app logs are as below, even though am explicitly issuing a rollback, it doesn't effct cause while the commit fails it seems the transaction is inactivated.</p>
  
  <pre><code>Is Tran ACtive? true // Before issuing commit()
  Exception while Committing - Is Tran ACtive? false // Tran status after commit() failed
  Exception while Committing, check-- &gt;javax.persistence.RollbackException:  // error  thrown while committing
  Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): 
  org.eclipse.persistence.exceptions.DatabaseException
  Internal Exception: com.sybase.jdbc3.jdbc.SybBatchUpdateException: JZ0BE: 
  BatchUpdateException: Error occurred while executing batch statement:
   Attempt to insert duplicate key row in object 'x' with unique index 'pk_x'
  </code></pre>