2

I have been trying to run JPA 2.0 in Tomcat 6.0.24 following this tutorial online: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial

So far it worked to retrieve a datasource and run a select statement. Query aQuery = em.createQuery("select e from Employee e"); empList = aQuery.getResultList();

But it failed when I tried to call entityManager.persist(employee). The code looked like this:

try {
em.getTransaction().begin();
    em.persist(emp);
em.getTransaction().commit();
} catch (Exception ex) {
ex.printStackTrace();
em.getTransaction().rollback();
}

I am getting this exception in the console:

[EL Finest]: jpa: 2012-12-08 16:17:16.38--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Begin predeploying Persistence Unit jpaOrclJtaPU; session file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU; state Initial; factoryCount 0
[EL Finest]: properties: 2012-12-08 16:17:16.396--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: properties: 2012-12-08 16:17:16.397--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.multitenant.tenants-share-emf; default value=true
[EL Finest]: properties: 2012-12-08 16:17:16.397--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.multitenant.tenants-share-cache; default value=false
[EL Finer]: metadata: 2012-12-08 16:17:16.422--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Searching for default mapping file in file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/ (There is no English translation for this message.)
[EL Finer]: metadata: 2012-12-08 16:17:16.428--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Searching for default mapping file in file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/ (There is no English translation for this message.)
[EL Config]: metadata: 2012-12-08 16:17:16.606--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--The access type for the persistent class [class com.arb.my.domain.Employee] is set to [FIELD].
[EL Config]: metadata: 2012-12-08 16:17:16.637--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--The alias name for the entity class [class com.arb.my.domain.Employee] is being defaulted to: Employee.
[EL Config]: metadata: 2012-12-08 16:17:16.64--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--The table name for entity [class com.arb.my.domain.Employee] is being defaulted to: EMPLOYEE.
[EL Finest]: jpa: 2012-12-08 16:17:16.672--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--End predeploying Persistence Unit jpaOrclJtaPU; session file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU; state Predeployed; factoryCount 0
[EL Finer]: weaver: 2012-12-08 16:17:16.673--Thread(Thread[http-bio-8082-exec-4,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: jpa: 2012-12-08 16:17:16.673--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Begin predeploying Persistence Unit jpaOrclJtaPU; session file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU; state Predeployed; factoryCount 0
[EL Finest]: jpa: 2012-12-08 16:17:16.673--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--End predeploying Persistence Unit jpaOrclJtaPU; session file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU; state Predeployed; factoryCount 1
[EL Finest]: jpa: 2012-12-08 16:17:16.683--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Begin deploying Persistence Unit jpaOrclJtaPU; session file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU; state Predeployed; factoryCount 1
[EL Finer]: 2012-12-08 16:17:16.692--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
[EL Finest]: properties: 2012-12-08 16:17:16.696--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: properties: 2012-12-08 16:17:16.696--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: properties: 2012-12-08 16:17:16.696--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.target-database; value=Oracle11; translated value=org.eclipse.persistence.platform.database.oracle.Oracle11Platform
[EL Finest]: properties: 2012-12-08 16:17:16.712--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.jdbc.batch-writing; value=Oracle-JDBC; translated value=Oracle-JDBC
[EL Finest]: properties: 2012-12-08 16:17:16.713--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--property=eclipselink.session.customizer; value=com.arb.my.util.JPAEclipseLinkSessionCustomizer
_JPAEclipseLinkSessionCustomizer: configured java:comp/env/jdbc/EmployeeDS
[EL Info]: 2012-12-08 16:17:16.717--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.4.1.v20121003-ad44345
[EL Config]: connection: 2012-12-08 16:17:16.806--ServerSession(10229612)--Connection(25559254)--Thread(Thread[http-bio-8082-exec-4,5,main])--connecting(DatabaseLogin(
    platform=>Oracle11Platform
    user name=> ""
    connector=>JNDIConnector datasource name=>java:comp/env/jdbc/EmployeeDS
))
[EL Config]: connection: 2012-12-08 16:17:17.121--ServerSession(10229612)--Connection(8689654)--Thread(Thread[http-bio-8082-exec-4,5,main])--Connected: jdbc:oracle:thin:@127.0.0.1:1521:xe
    User: MH
    Database: Oracle  Version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta
    Driver: Oracle JDBC driver  Version: 11.2.0.2.0
[EL Finest]: connection: 2012-12-08 16:17:17.121--ServerSession(10229612)--Connection(18129670)--Thread(Thread[http-bio-8082-exec-4,5,main])--Connection acquired from connection pool [read].
[EL Finest]: connection: 2012-12-08 16:17:17.122--ServerSession(10229612)--Connection(18129670)--Thread(Thread[http-bio-8082-exec-4,5,main])--Connection released to connection pool [read].
[EL Config]: connection: 2012-12-08 16:17:17.122--ServerSession(10229612)--Connection(31133089)--Thread(Thread[http-bio-8082-exec-4,5,main])--connecting(DatabaseLogin(
    platform=>Oracle11Platform
    user name=> ""
    connector=>JNDIConnector datasource name=>java:comp/env/jdbc/EmployeeDS
))
[EL Config]: connection: 2012-12-08 16:17:17.122--ServerSession(10229612)--Connection(6019448)--Thread(Thread[http-bio-8082-exec-4,5,main])--Connected: jdbc:oracle:thin:@127.0.0.1:1521:xe
    User: MH
    Database: Oracle  Version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta
    Driver: Oracle JDBC driver  Version: 11.2.0.2.0
[EL Info]: connection: 2012-12-08 16:17:17.632--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU login successful
[EL Finer]: metamodel: 2012-12-08 16:17:17.658--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--Canonical Metamodel class [com.arb.my.domain.Employee_] not found during initialization.
[EL Finest]: jpa: 2012-12-08 16:17:17.658--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--End deploying Persistence Unit jpaOrclJtaPU; session file:/C:/eclipseProjects/workspaces/JPA4ORCL/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/JPAStruts1310Web/WEB-INF/classes/_jpaOrclJtaPU; state Deployed; factoryCount 1
[EL Finer]: connection: 2012-12-08 16:17:17.679--ServerSession(10229612)--Thread(Thread[http-bio-8082-exec-4,5,main])--client acquired: 7060068
[EL Finer]: transaction: 2012-12-08 16:17:17.692--ClientSession(7060068)--Thread(Thread[http-bio-8082-exec-4,5,main])--acquire unit of work: 9790036
[EL Finest]: transaction: 2012-12-08 16:17:17.692--UnitOfWork(9790036)--Thread(Thread[http-bio-8082-exec-4,5,main])--persist() operation called on: com.arb.my.domain.Employee@16aa42e.
[EL Finer]: transaction: 2012-12-08 16:17:17.694--UnitOfWork(9790036)--Thread(Thread[http-bio-8082-exec-4,5,main])--begin unit of work commit
[EL Finest]: query: 2012-12-08 16:17:17.702--UnitOfWork(9790036)--Thread(Thread[http-bio-8082-exec-4,5,main])--Execute query InsertObjectQuery(com.arb.my.domain.Employee@16aa42e)
[EL Finest]: connection: 2012-12-08 16:17:17.704--ServerSession(10229612)--Connection(21263661)--Thread(Thread[http-bio-8082-exec-4,5,main])--Connection acquired from connection pool [default].
[EL Finer]: transaction: 2012-12-08 16:17:17.704--ClientSession(7060068)--Connection(21263661)--Thread(Thread[http-bio-8082-exec-4,5,main])--begin transaction
[EL Finest]: connection: 2012-12-08 16:17:17.705--ClientSession(7060068)--Thread(Thread[http-bio-8082-exec-4,5,main])--reconnecting to external connection pool
[EL Finer]: sql: 2012-12-08 16:17:17.705--ClientSession(7060068)--Connection(23651369)--Thread(Thread[http-bio-8082-exec-4,5,main])--Begin batch statements
[EL Fine]: sql: 2012-12-08 16:17:17.706--ClientSession(7060068)--Connection(23651369)--Thread(Thread[http-bio-8082-exec-4,5,main])--INSERT INTO EMPLOYEE (EMP_NO, EMP_FNAME, EMP_LNAME, JOIN_DATE) VALUES (?, ?, ?, ?)
[EL Fine]: sql: 2012-12-08 16:17:17.706--ClientSession(7060068)--Connection(23651369)--Thread(Thread[http-bio-8082-exec-4,5,main])--    bind => [4, Issa, Haque, null]
[EL Finer]: sql: 2012-12-08 16:17:17.706--ClientSession(7060068)--Connection(23651369)--Thread(Thread[http-bio-8082-exec-4,5,main])--End Batch Statements
[EL Finer]: transaction: 2012-12-08 16:17:17.831--ClientSession(7060068)--Connection(23651369)--Thread(Thread[http-bio-8082-exec-4,5,main])--rollback transaction
[EL Finest]: connection: 2012-12-08 16:17:17.832--ServerSession(10229612)--Connection(21263661)--Thread(Thread[http-bio-8082-exec-4,5,main])--Connection released to connection pool [default].
[EL Warning]: 2012-12-08 16:17:17.832--UnitOfWork(9790036)--Thread(Thread[http-bio-8082-exec-4,5,main])--java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement cannot be cast to oracle.jdbc.OraclePreparedStatement
    at org.eclipse.persistence.platform.database.oracle.Oracle9Platform.prepareBatchStatement(Oracle9Platform.java:747)
    at org.eclipse.persistence.internal.databaseaccess.ParameterizedSQLBatchWritingMechanism.prepareBatchStatements(ParameterizedSQLBatchWritingMechanism.java:180)
    at org.eclipse.persistence.internal.databaseaccess.ParameterizedSQLBatchWritingMechanism.executeBatchedStatements(ParameterizedSQLBatchWritingMechanism.java:144)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.writesCompleted(DatabaseAccessor.java:1714)
    at org.eclipse.persistence.internal.sessions.AbstractSession.writesCompleted(AbstractSession.java:3951)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.writesCompleted(UnitOfWorkImpl.java:5552)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.acquireWriteLocks(UnitOfWorkImpl.java:1624)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitTransactionAfterWriteChanges(UnitOfWorkImpl.java:1592)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:274)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1147)
    at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
    at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
    at com.arb.my.domain.controller.EmployeeManager.createEmployee(EmployeeManager.java:44)
    at com.arb.my.action.EmployeeDetailAction.execute(EmployeeDetailAction.java:37)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Any Idea why am I getting this exception? Any body else got this error before while running JPA? Any idea how to resolve this issue?

1 Answer 1

2

Ok, after banging my head for 72 hours, I figured it out myself (Patting myself on my back!)

I had this "Batch-writing" property to 'Oracle-JDBC' in persistence.xml. I changed it to 'JDBC' and it started working!

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> </persistence-unit>, java:comp/env/--> org.eclipse.persistence.jpa.PersistenceProvider java:comp/env/jdbc/EmployeeDS com.arb.my.domain.Employee

I hope it helps anybody who faces this issue in future.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.