Topic
  • No replies
RyanEvans
RyanEvans
1 Post

Pinned topic enJPA 2.0 and Log4j - Non OSGi

‏2011-12-20T19:44:28Z |
Hi,
I'm developing using RAD v8 with WAS 7.0.x and we recently added the Application server with Java Persistence API 2.0 feature to our server configuration. We have not implemented the OSGi framework on the server, nor are we using bundles to package our jar files in the project manifests.

My persistence.xml looks like this... trying to implement log4j as the logging framework.

<?xml version=
"1.0" encoding=
"UTF-8"?> <persistence version=
"2.0" xmlns=
"http://java.sun.com/xml/ns/persistence" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name=
"GutsJpa" transaction-type=
"JTA"> <jta-data-source>jdbc/gagutsDb2XADebuglogDS</jta-data-source> <class>com.metlife.us.ins.product.groupadmin.debuglog.jpadata.TProbAnalBusData</class> <class>com.metlife.us.ins.product.groupadmin.debuglog.jpadata.TProbAnalBusDataPK</class> <class>com.metlife.us.ins.product.groupadmin.debuglog.jpadata.TProbAnalLog</class> <properties> <property name=
"openjpa.jdbc.Schema" value=
"K207DBA"/> <property name=
"openjpa.Log" value=
"log4j"/> </properties> </persistence-unit> </persistence>

the log4j.jar is in the manifest file for the Jpa project as it is for all of the projects on my workspace. An example of what my manifest looks like is this

Manifest-Version: 1.0 Class-Path: GutsCommon.jar commons-logging-1.1.1.jar log4j-1.2.14.jar

When I run code on the server that tries to insert into the database using the JPA persistence entities I get the following error

2011-12-19 13:24:06,650 DEBUG groupadmin.gutsmdb.logging.DebugLogMDB - L1238158    

null   ABCDEFG         12345   1010    Could not insert into database: java.lang.ClassNotFoundException message: org.apache.log4j.Priority: org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:402) org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:347) org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83) java.lang.ClassLoader.loadClass(ClassLoader.java:626) java.lang.J9VMInternals.verifyImpl(Native Method) java.lang.J9VMInternals.verify(J9VMInternals.java:72) java.lang.J9VMInternals.initialize(J9VMInternals.java:134) org.apache.openjpa.lib.log.Log4JLogFactory.newLogAdapter(Log4JLogFactory.java:33) org.apache.openjpa.lib.log.LogFactoryAdapter.getLog(LogFactoryAdapter.java:40) org.apache.openjpa.lib.conf.ConfigurationImpl.getLog(ConfigurationImpl.java:226) org.apache.openjpa.conf.OpenJPAConfigurationImpl.getConfigurationLog(OpenJPAConfigurationImpl.java:1619) org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationProviderImpl.setInto(PersistenceProductDerivation.java:696) com.ibm.ws.persistence.jdbc.kernel.WsJpaJDBCBrokerFactory.newInstance(WsJpaJDBCBrokerFactory.java:129) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) java.lang.reflect.Method.invoke(Method.java:611) org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:124) org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:62) org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:148) org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:94) com.ibm.websphere.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:73) com.ibm.websphere.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:43) org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:154) org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:65) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:150) javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:70) com.metlife.us.ins.product.groupadmin.common.db.DbUtils.getEntityManagerFactory(DbUtils.java:35) com.metlife.us.ins.product.groupadmin.common.db.BaseDAO.createEntityManagerFactory(BaseDAO.java:73) com.metlife.us.ins.product.groupadmin.common.db.BaseDAO.getEntityManager(BaseDAO.java:62) com.metlife.us.ins.product.groupadmin.common.db.BaseDAO.insertWithinTransaction(BaseDAO.java:152) com.metlife.us.ins.product.groupadmin.gutsmdb.logging.DebugLogUtils.insertDebugLog(DebugLogUtils.java:32) com.metlife.us.ins.product.groupadmin.gutsmdb.logging.DebugLogMDB.processJAXBObject(DebugLogMDB.java:33) com.metlife.us.ins.product.groupadmin.gutsmdb.logging.DebugLogMDB.processJAXBObject(DebugLogMDB.java:1) com.metlife.us.ins.product.groupadmin.common.mq.XMLBaseListenerBean.process(XMLBaseListenerBean.java:35) com.metlife.us.ins.product.groupadmin.common.mq.MDBBaseListenerBean.onMessage(MDBBaseListenerBean.java:58)

I think what is happening is the OSGi classloader is looking for the log4j.jar inside an OSGI bundle, but since we haven't implmented OSGi it doesn't find the log4j.jar and throws a ClassNotFound Exception. I'm wondering if anyone has seen this with JPA 2.0, if my hunch is correct and if so what resolution is required.