Faz
Faz

Reputation: 554

JPA ECLIPSELINK issues SELECT 1

All,

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?

Please let me know why does this happen and is there a way to get past this?
Thanks!

[UPDATE]
Sure, its RESOURCE_LOCAL and I use JPAEclipseCustmizer to set the connection,

<persistence version="2.0" ...>
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
....
<properties> 
<property name="eclipselink.session.customizer" value="xxx.JpaEclipseLinkSessionCustomizer" />
</properties> 

And the error log, if you notice, there is no trace of end unit of work commit 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

[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'

Error Code: 0
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeJDK12BatchStatement(DatabaseAccessor.java:830)

[UPDATE 2]
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.
I get to see the below in the db logs,

 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  

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).

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.

Is Tran ACtive? true // Before issuing commit()
Exception while Committing - Is Tran ACtive? false // Tran status after commit() failed
Exception while Committing, check-- >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'

Upvotes: 2

Views: 1176

Answers (1)

V G
V G

Reputation: 19002

That is not the cause of your problems. It comes from your connection pool manager, that keeps the connection alive. Such a query cannot lock any table, as no table is involved.

Probably you should close the EntityManager (even if an exception occurs).

Upvotes: 1

Related Questions