I am working on a new project that has a really messed up classpath jars.I was trying to run a class in local when i came accross this error InCompatibleClassChangeError.
The logs looked somewhat like this..
The logs looked somewhat like this..
Exception in thread "main" org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'
defined in class path resource [commonApplicationContextJPA.xml]:
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [commonApplicationContextJPA.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:127)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:71)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:268)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) Baffled by it, I started to look what exactly is going on.So I searched google and found what exactly InCompatibleClassChangeError is and I found this..This is a complete list of changes in Java library API that may cause clients built with an old version of the library to throw java.lang.IncompatibleClassChangeError if they run on a new one (i.e. breaking BC):
- Non-final field become static,
- Non-constant field become non-static,
- Class become interface,
- Interface become class,
- if you add a new field to class/interface (or add new super-class/super-interface) then a static field from a super-interface of a client class C may hide an added field (with the same name) inherited from the super-class of C (very rare case).
By this time, I was sure that definitely there is some mismatch between the version of some jar.I started looking for mismatch in the spring versions, tried everything i could to make the spring version of entire project to one version but no luck.
Then i googled more and found that, such error comes for hibernate when tow different hibernate versions are present.Finally, i found i built maven dependency tree using "mvn dependency:tree" and searched for two different versions of hibernate.And voila,there were two of them.Finally,i excluded the older version using this and the exception went away.I am happy now.I have learnt to approach problems in a more practical way.
<Exclusion><GroupId> org.hibernate </ groupId><ArtifactId> Hibernate </ artifactId></ Exclusion><Exclusion><GroupId> org.hibernate </ groupId><ArtifactId> hibernate-commons-annotations </ artifactId></ Exclusion>