Problem : When performing the transaction in application (Deployed in web logic (10.3.6.0) Caused by: java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider
Solution :
Web.xml:
Add customer listener class to resolve the persistence provider.
<listener>
<listener-class>com.kewill.bluedart.weblogic.POSWeblogicPresistenceListener</listener-class>
</listener>
POSWeblogicPresistenceListener.java (Customer Listener class):
package com.kewill.bluedart.weblogic;
import javax.servlet.ServletContextEvent;
public class POSWeblogicPresistenceListener implements javax.servlet.ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent arg0) {
HibernatePersistenceProviderResolver.register();
}
}
HibernatePersistenceProviderResolver.java (Custom Persistence provider resolver class):
package com.kewill.bluedart.weblogic;
import java.util.Collections;
import java.util.List;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceProviderResolver;
import javax.persistence.spi.PersistenceProviderResolverHolder;
import org.apache.log4j.Logger;
import org.hibernate.ejb.HibernatePersistence;
public class HibernatePersistenceProviderResolver implements
PersistenceProviderResolver {
private static final Logger LOGGER = Logger.getLogger(HibernatePersistenceProviderResolver.class.getName());
private volatile PersistenceProvider persistenceProvider = new HibernatePersistence();
@Override
public List<PersistenceProvider> getPersistenceProviders() {
return Collections.singletonList(persistenceProvider);
}
@Override
public void clearCachedProviders() {
persistenceProvider = new HibernatePersistence();
}
public static void register() {
LOGGER.info("Registering HibernatePersistenceProviderResolver");
PersistenceProviderResolverHolder
.setPersistenceProviderResolver(new HibernatePersistenceProviderResolver());
}
}
webloigc.xml (Weblogic delopyment descriptor):
<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd"
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<container-descriptor>
<index-directory-enabled>true</index-directory-enabled>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.springframework.*</package-name>
<package-name> org.apache.commons.*</package-name>
<package-name>org.apache.xmlbeans.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>org.hibernate.validator.*</package-name>
<package-name>javax.persistence.*</package-name>
<package-name>org.joda.*</package-name>
<package-name>com.sun.xml.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/spring.handlers</resource-name>
</prefer-application-resources>
</container-descriptor>
<context-root>user context path</context-root>
</weblogic-web-app>
Do all the above changes. weblogic.xml : will change as per your project dependencies. No i resolved the above issue. I hope it will helps you to resolve the same.
Solution :
Web.xml:
Add customer listener class to resolve the persistence provider.
<listener>
<listener-class>com.kewill.bluedart.weblogic.POSWeblogicPresistenceListener</listener-class>
</listener>
POSWeblogicPresistenceListener.java (Customer Listener class):
package com.kewill.bluedart.weblogic;
import javax.servlet.ServletContextEvent;
public class POSWeblogicPresistenceListener implements javax.servlet.ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent arg0) {
HibernatePersistenceProviderResolver.register();
}
}
HibernatePersistenceProviderResolver.java (Custom Persistence provider resolver class):
package com.kewill.bluedart.weblogic;
import java.util.Collections;
import java.util.List;
import javax.persistence.spi.PersistenceProvider;
import javax.persistence.spi.PersistenceProviderResolver;
import javax.persistence.spi.PersistenceProviderResolverHolder;
import org.apache.log4j.Logger;
import org.hibernate.ejb.HibernatePersistence;
public class HibernatePersistenceProviderResolver implements
PersistenceProviderResolver {
private static final Logger LOGGER = Logger.getLogger(HibernatePersistenceProviderResolver.class.getName());
private volatile PersistenceProvider persistenceProvider = new HibernatePersistence();
@Override
public List<PersistenceProvider> getPersistenceProviders() {
return Collections.singletonList(persistenceProvider);
}
@Override
public void clearCachedProviders() {
persistenceProvider = new HibernatePersistence();
}
public static void register() {
LOGGER.info("Registering HibernatePersistenceProviderResolver");
PersistenceProviderResolverHolder
.setPersistenceProviderResolver(new HibernatePersistenceProviderResolver());
}
}
webloigc.xml (Weblogic delopyment descriptor):
<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.1/weblogic-web-app.xsd"
xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<container-descriptor>
<index-directory-enabled>true</index-directory-enabled>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.springframework.*</package-name>
<package-name> org.apache.commons.*</package-name>
<package-name>org.apache.xmlbeans.*</package-name>
<package-name>org.hibernate.*</package-name>
<package-name>org.hibernate.validator.*</package-name>
<package-name>javax.persistence.*</package-name>
<package-name>org.joda.*</package-name>
<package-name>com.sun.xml.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/spring.handlers</resource-name>
</prefer-application-resources>
</container-descriptor>
<context-root>user context path</context-root>
</weblogic-web-app>
Do all the above changes. weblogic.xml : will change as per your project dependencies. No i resolved the above issue. I hope it will helps you to resolve the same.
No comments:
Post a Comment