java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider"" - java

I was upgrading spring 3.x to 5.3.x version in my project. Done some spring 5.3.x specific changes and deployed the build. Then following exception came:
Exception:"Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: javax.persistence.Converter"
Solution applied: added hibernate-jpa-2.1-api-1.0.0.Final as a solution.
Next following exception came:
"java.lang.ClassNotFoundException: org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"
In spring docs, I could see ,OpenJpaVendorAdaptor is removed from spring5.x and jpa 2.1 compliant persistence provider is needed. when searching, could see using eclipselink is one of the solution instead of OpenJpa.
For which I have changed, org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter to org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter and in persistence.xml added org.eclipse.persistence.jpa.PersistenceProvider as provider tag.Then eclipselink-2.6.4 dependency added as gradle dependency.
could see jar is getting generated , but classes from jar is not picking up. getting following error on code compilation:
"Starting the enhancement task
[ant:openjpac] WARNING: Unable to load persistence provider "org.eclipse.persistence.jpa.PersistenceProvider" due to "java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider""
Please help.

Related

Application Deployment failing on cloud foundry due to entityManagerFactory bean creation failed

I am facing below error while deploying spring boot microservice on cloud foundry:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/ge/pd/reports/config/HibernateConfig.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
As I checked many resolution on stack overflow and many other portals for the solution, All the solution are related to jar version conflicts.
I have eliminated all the conflicts jar from the application and updated with all the jar versions which is required.
I am using below jar and its version:
hibernate-core-5.0.12.Final.jar - 5.0.12
hibernate-jpa-2.1-api-1.0.0.Final.jar - 2.1
hibernate-entitymanager-5.0.12.Final.jar - 5.0.12
openjpa-2.4.0.jar - 2.4.0
Please Provide the Solution.
This indeed looks like a dependency conflict, more specifically, between Hibernate 5.0.12 (which uses JPA 2.1) and OpenJPA 2.4.0 (which uses JPA 2.0). Try removing the OpenJPA dependency.
As this SO thread shows, the said method was introduced in JPA 2.1.

Spring Boot 2 Upgrade not able to resolve class name as property

We have an application where one of our internal libraries has defined a bean like this
<bean id="myBean" class="${myBean.type}"/>
We have a Spring Cloud Config Server which feeds properties to this application on startup, which also contains the property myBean.type. This setup is currently working fine with no issues. I then made the following change to my pom
Earlier
<spring.boot.version>1.5.16.RELEASE</spring.boot.version>
<spring.cloud.version>Edgware.RELEASE</spring.cloud.version>
<spring.version>4.3.19.RELEASE</spring.version>
Now
<spring.boot.version>2.0.9.RELEASE</spring.boot.version>
<spring.version>5.0.13.RELEASE</spring.version>
<spring.cloud.version>Finchley.SR2</spring.cloud.version>
Then I started getting this error on startup
An attempt was made to call the method org.springframework.beans.factory.support.BeanDefinitionBuilder.addConstructorArg(Ljava/lang/Object;)Lorg/springframework/beans/factory/support/BeanDefinitionBuilder; but it does not exist. Its class, org.springframework.beans.factory.support.BeanDefinitionBuilder, is available from the following locations:
jar:file:/I:/Library/MavenRepository/org/springframework/spring-beans/5.0.13.RELEASE/spring-beans-5.0.13.RELEASE.jar!/org/springframework/beans/factory/support/BeanDefinitionBuilder.class
It was loaded from the following location:
file:/I:/Library/MavenRepository/org/springframework/spring-beans/5.0.13.RELEASE/spring-beans-5.0.13.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.beans.factory.support.BeanDefinitionBuilder
Looking at this, I excluded the artifact org.apache.cxf:cxf-api:jar:2.7.18:compile from all the jars that depended on it & upgraded cxf jars versions to 3.2.5. Now the startup is going ahead but it is giving me the following error:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [${myBean.type}] for bean with name 'myBean' defined in class path resource [xyz.xml]; nested exception is java.lang.ClassNotFoundException: ${myBean.type}
I am not sure if removal of cxf-api is causing this issue, or upgrade of Spring Boot 2, or is it something else that is going wrong here!

Moving Java web application from JBoss to Websphere - getting exceptions when building Maven errors

Resource annotations on the fields of the org.springframework.web.servlet.DispatcherServlet class will be ignored. The annotations could not be obtained because of the exception :
java.lang.NoClassDefFoundError: org.springframework.web.context.WebApplicationContext
I am also seeing some Maven dependency errors when I performed a Maven build, Can you please help how I can resolve these classpath errors
using spring-core-4.1.4.release.jar, spring-webmvc-4.1.4.RELEASE.jar
Error #2 - This is another error being displayed, which may be related to above error,
javax.servlet.UnavailableException: SRVE0203E: Servlet [appServlet]: org.springframework.web.servlet.DispatcherServlet was found, but is missing another required class.
SRVE0206E: This error typically implies that the servlet was originally compiled with classes which cannot be located by the server.
Your application clearly needs the Spring framework and can't find it. It either needs to be deployed as part of the EAR/WAR, or configured as a shared library in your server and mapped to your application.

unitils-orm-hibernate not working with Hibernate 5

I'm using unitils for hibernate orm testing. I took the hibernate version 5.0.10-Final and the latest unitils version 3.4.3.
I'm always getting the following error: "org.unitils.core.UnitilsException: An exception occured during the loading of core module hibernate with module class name org.unitils.orm.hibernate.HibernateModule -> Caused by: org.unitils.core.UnitilsException: Could not load class with name org.hibernate.cfg.AnnotationConfiguration"
When I look into the code I can see (in older version of Hibernate 4) that the AnnotationConfiguration is deprecated and will be replaced in Hibernate 5. Apparently the unitils still expects the class to be there as the property 'HibernateModule.configuration.implClassName' still points towards this class.
Do I need an other configuration? Or an other version?
You just need to add to unitils configuration next line:
HibernateModule.configuration.implClassName=org.hibernate.cfg.Configuration

Datanucleus RDBMS JPA jar-with-dependencues

I configured and I use Datanucleus JPA to connect to MySQL. I compile the classes and enhanced entities with datanucleus-enhancer-plugin. I can run my app using mvn exec:java and I can also run it after I create an archive with lib (jar dependencies).
The problem appears when I create a jar (jar-with-dependencies). I get this error:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "mysql" after trying the following discovered implementations: org.datanucleus.api.jpa.PersistenceProviderImpl from provider: org.datanucleus.api.jpa.PersistenceProviderImpl
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at cantina.crawler.util.JpaUtil.getRdbmsEntityManager(JpaUtil.java:29)
at cantina.crawler.bolt.SiteDetectorBolt.prepare(SiteDetectorBolt.java:32)
at backtype.storm.daemon.executor$fn__4050$fn__4059.invoke(executor.clj:610)
at backtype.storm.util$async_loop$fn__465.invoke(util.clj:375)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.datanucleus.exceptions.NucleusException: Error creating handler of type "persistence" for metadata parsing : MetaData handler plugin "persistence" was not found. Please check your CLASSPATH and plugin specification.
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataStream(MetaDataParser.java:269)
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataURL(MetaDataParser.java:137)
at org.datanucleus.metadata.MetaDataUtils.parsePersistenceFiles(MetaDataUtils.java:956)
at org.datanucleus.api.jpa.JPAEntityManagerFactory.<init>(JPAEntityManagerFactory.java:342)
at org.datanucleus.api.jpa.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
... 6 more
Caused by: org.datanucleus.exceptions.NucleusUserException: MetaData handler plugin "persistence" was not found. Please check your CLASSPATH and plugin specification.
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataStream(MetaDataParser.java:263)
... 11 more
I unziped the jar and the datanucleus-core files are there. I can not figure out what is happening.
You've not bothered looking after MANIFEST.MF and plugin.xml files when you changed the jar(s). DataNucleus jars are packaged to allow the (OSGi-based) plugin mechanism to identify plugins and capabilities. You've disabled that by playing around with those jars, so get the consequences.
Solution : either use the jars as provided, or merge them correctly (in which case it's your responsibility)

Categories

Resources