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
Related
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.
When I try to build my Enterprise Project in Netbeans with ant, i got this exception:
warning: Supported source version 'RELEASE_6' from annotation
processor
'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor'
less than -source '1.8'
Note: Creating static metadata factory ...
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file
javax/persistence/PersistenceException
I only have some entityclasses in my ejb module.
This error is reported as a bug in NetBeans (with a resolved status as it turns out to be considered as a "user error"). Below is the main comment that explains the problem and gives the solution:
"ClassFormatError: Absent Code attribute in method..." is always indication that javaee-api-6.0.jar is used for runtime execution. The jar contains only method signatures (method bodies are stripped) and is suitable only for compilation. In future versions of javac there might be better error message.
The problem here is that javaee-api-6.0.jar is on classpath before EclipseLink jars and when EclipseLink annotation processor is started classes from javaee-api-6.0.jar are used instead of classes from EclipseLink. First thing is that javaee-api-6.0.jar should be removed from classpath of EJB project - it should not be needed as EJB project has an Application server selected and the project takes EE 6 APIs from that server.
As I understand the comment, you should try removing any reference to javaee-api-6.0.jar (which contains only "dummy" classes) from the classpath of the project, because the EclipseLink library should provide the correct classes used by the annotation processor.
Also, this question seems to tackle the same issue.
when you use the insert code and automatic bean creation it adds the Java EE 6
API library . I deleted the library and add the Java EE 7 API.
My web application is tightly integrated with Spring 4.3 / Hibernate 5.1.
My main SessionFactory object is handled by a factory that extends org.springframework.orm.hibernate5.LocalSessionFactoryBean.
On the afterPropertiesSet of the LSFB, Hibernate scans for modules and services.
I am currently getting the following error when the Jadira jar file is present in the web classpath
Caused by: java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator not found
at java.util.ServiceLoader.fail(ServiceLoader.java:231)
at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:340)
at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:40)
at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:213)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.getMetadataSources(LocalSessionFactoryBean.java:364)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:399)
at com.acme.AnnotationSessionFactoryBean.afterPropertiesSet(AnnotationSessionFactoryBean.java:203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 35 more
I am now investigating this. Looks like there is a classloader problem because of something I couldn't understand yet.
I have been digging into Spring and Hibernate code.
LocalSessionFactoryBean's afterPropertiesSet invokes constructor of LocalSessionFactoryBuilder using default MetadataSources
getMetadataSources, when invoked for the first time, builds a BootstrapServiceRegistryBuilder using ClassLoader from resourcePatternResolver, which is the WebappClassLoader (who can look into Jars)
When code digs into ServiceLoader class, it tries to instantiate class org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator using ClassLoader org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader#70d5297f
The code breaks into the following line which I can't debug despite the Java sources
try {
c = Class.forName(cn, false, loader);
} catch (ClassNotFoundException x) {
[OP: exception is swallowed]
fail(service,
"Provider " + cn + " not found");
}
I don't understand why this happens.
Is there anything particular to do in order to load Hibernate services? How can one treat those ServiceConfigurationErrors?
The problem was simply due to Java version mismatch and the ClassNotFoundException being swallowed by ServiceRegistry.
It happens (I did not mention) that Jadira 6.x requires Java 8 / Hibernate 5.2 but I am using Java 7.
The root cause of CNFE is UnsupportedClassVersionError which can be obtained by running a simple main trying to instantiate the desired service class. Running the application on Java 8 helps understand this (as the error is API incompatibility with HB 5.1), so I just had to downgrade Jadira to 5.x
Websphere 8.0.0.11
Hibernate 4.2.21.Final
I have found many questions about this same problem but none of them worked for me.
If I deploy the application in Websphere it works OK.
However we have defined a shared library that contains all the third party libraries (spring, hibernate, javassist, etc) so that our WARs are thinner.
This way during deployment we associate our thin WAR against that Websphere shared library.
The point is that when we deploy the application this way the ClassCastException Hibernate exception _$$_javassist_856 cannot be cast to javassist.util.proxy.Proxy is thrown.
I have checked the loaded jars in the websphere console and can only see one javassist jar (3.18.1-GA) in the classpath.
Why could this be happening?
UPDATE
I have also tried using PARENT_FIRST and PARENT_LAST class loading.
UPDATE 2
I just found out that Websphere is loading its own javassist jar:
URL location = ProxyFactory.class.getProtectionDomain().getCodeSource().getLocation();
logger.info("{}", location);
It prints: file:/opt/IBM/WebSphere/AppServer/plugins/javassist.jar
After trying pretty much everything I found on S.O. without any success I decided to downgrade Hibernate to version 4.1.12.Final. This is the maximum 4.x version compatible with Websphere 8.x.
The problem is that Javassist leaves traces in its generated code. With Javassist on the class path twice, its classes are loaded twice. Two types are however only equal if they have the same name and are loaded by the same class loader. In your case, the generated class resolves its Javassist dependeny to a type that is loaded by your application class loader while your code is casting the instance to the Javassist type that is loaded by the Websphere class loader (or the other way around).
Are you sharing any Hibernate dependencies between applications? Try to not use any shared libraries related to Hibernate in your application to avoid this.
I am trying to use validation with Spring 3.x.
I have annotated a method field with #Valid, added <mvc:annotation-driven/> to my common.xml, and added Hibernate-Validator.jar in the lib/ dir, but I keep getting this message: "Hibernate validator not found: ignoring".
Am I missing something?
[Version:15] Hibernate Annotations 3.4.0.GA
[Environment:543] Hibernate 3.3.0.SP1
[Environment:576] hibernate.properties not found
[Environment:709] Bytecode provider name : javassist
[Environment:627] using JDK 1.4 java.sql.Timestamp handling
[Version:14] Hibernate Commons Annotations 3.1.0.GA
[AnnotationConfiguration:369] Hibernate Validator not found: ignoring
It means that Hibernate can't find the classes org.hibernate.validator.ClassValidator or org.hibernate.validator.MessageInterpolator, hinting that there's a problem with the library versions in your classpath.
I see you're using the following versions:
Hibernate Annotations 3.4.0.GA
Hibernate 3.3.0.SP1
Hibernate Commons Annotations 3.1.0.GA
And your JAR is hibernate-validator-4.0.2.GA.jar. Are you sure that all of these versions are compatible with each other?
Please try downloading the newest versions of the different Hibernate components, put them in your classpath and see if the error is still there.
At last, I found the answer at Spring ROO Issue Tracker
it is a bug in Hibernate that is
known to be corrected in Hibernate 3.5
I've this message too in my Spring project, but validation still works.