miércoles, 15 de octubre de 2014

ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration redeploying Hibernate app in WebLogic


The following error occured after redeploying (updating) an app in WebLogic (which worked OK in the first deployment) and trying to use some persistence functionality:

Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.XIncludeAwareParserConfiguration
at org.apache.xerces.parsers.SAXParser.(Unknown Source)
at org.apache.xerces.parsers.SAXParser.(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.(Unknown Source)
at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source)
at org.apache.openjpa.lib.xml.XMLFactory.getSAXParser(XMLFactory.java:81)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource(XMLMetaDataParser.java:352)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:320)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:296)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:268)
at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationParser.parse(PersistenceProductDerivation.java:591)
at org.apache.openjpa.persistence.PersistenceProductDerivation.parseResources(PersistenceProductDerivation.java:368)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:333)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:162)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:77)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:109)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:53)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.acme.jpa.EntityManagerSinglenton.(EntityManagerSinglenton.java:14)
    ...

The problematic line is:

EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory(this.unitPersistence);

The application developers want to use Hibernate. Their persistence.xml's declare org.hibernate.ejb.HibernatePersistence as the persistence units provider. They are including the Hibernate jars in the app (through a WebLogic shared library). WebLogic version is 12.1.1. Besides the following configuration, they don't have any other related configuration in the app:

<wls:prefer-application-packages>
    <wls:package-name>antlr.*</wls:package-name>
</wls:prefer-application-packages>

Taking advantage of the fact that they just want to use Hibernate and the stack trace shows OpenJPA classes, I included the following configuration in weblogic-application.xml:

<wls:prefer-application-resources>
    <wls:resource-name>META-INF/services/javax.persistence.spi.PersistenceProvider</wls:resource-name>
</wls:prefer-application-resources>

Warning: I'm in the process of validating if this is a "good" solution or just a "dirty" one (as probably is).




No hay comentarios: