JPA as a multithread

ERROR [ACTIVE] ExecuteThread: '33' for queue: 'weblogic.kernel.Default (self-tuning)' - 07.02.2014 11:37:20,360 request_id=9e32efa6-1374-4b1c-99e9-326a3a256b88 Error Code:99 Error in Async Task with delay 0 :

Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Statement has already been closed Error Code: 0 Call: SELECT ID, FIRST_NAME, ISBLOCKED, LAST_NAME, MODIFIED, MSISDN, VERSION, OWNER_ID, CONTACT_ID FROM CONTACTS WHERE (OWNER_ID = ?) bind => [1 parameter bound] Query: ReadAllQuery(name="VasServerfile:/data/msgadmin/wls12c/wlserver_12.1/domains/VAS-MSG-TST-DMN/servers/VAS-MSG-TST-M1-MAN1-1/tmp/_WL_user/VasServer/c7nfil/war/WEB-INF/lib/_wl_cls_gen.jar_VasServerPU" referenceClass=Contact sql="SELECT ID, FIRST_NAME, ISBLOCKED, LAST_NAME, MODIFIED, MSISDN, VERSION, OWNER_ID, CONTACT_ID FROM CONTACTS WHERE (OWNER_ID = ?)") at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535) at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717) at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264) at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:646) at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2611) at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2570) at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:420) at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1081) at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844) at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1040) at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:392)

I am trying to use JPA Multithread but I took this kind of exceptions, any idea to solve the problem.

thanks

Answers


EntityManager is not thread safe, so you should use an EntityManager instance in a single thread. In different threads you could use a EntityManagerFactory instance, as it is thread-safe.


If you want to isolate different HTTP threads (I mean each http thread has it's own entityManager) and you have web app you can use OpenEntityMangerInView filter.

web.xml fragment:

<filter>
    <filter-name>oemInViewFilter</filter-name>
    <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    <init-param>
        <param-name>entityManagerFactoryBeanName</param-name>
        <param-value>entityManagerFactory</param-value>
    </init-param>
</filter>

You can also try OpenEntityManagerInViewInterceptor:

http://javadox.com/org.springframework/spring-orm/3.2.6.RELEASE/org/springframework/orm/jpa/support/OpenEntityManagerInViewInterceptor.html


Need Your Help

Tricky programming problem that I'm having trouble getting my head around

algorithm math numbers np-complete

First off, let me say that this is not homework (I am an A-Level student, this is nothing close to what we problem solve (this is way harder)), but more of a problem I'm trying to suss out to impro...

Microsoft Chart control in WinForms app - how to display a composite chart

winforms visual-studio-2010 charts

I need to display a chart showing per-month sales; I want to display the volume as one column and the sales as a different column (both in each month). The problem, however, is that I have multiple...