I know this question already has answers but I am unable to resolve my issue.
I have hibernate-commons-annotations-5.0.1.Final.jar, hibernate-core-4.3.5.Final.jar, hibernate-jpa-2.1-api-1.0.0.final.jar in the classpath.
Following is my HibernateUtil code:
public class HibernateUtil {
private static SessionFactory sessionAnnotationFactory;
private static SessionFactory buildSessionAnnotationFactory() {
try {
// Create the SessionFactory from hibernate-annotation.cfg.xml
Configuration configuration = new Configuration();
configuration.configure("hibernate-annotation.cfg.xml");
System.out.println("Hibernate Annotation Configuration loaded");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
System.out.println("Hibernate Annotation serviceRegistry created");
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionAnnotationFactory() {
if (sessionAnnotationFactory == null) sessionAnnotationFactory = buildSessionAnnotationFactory();
return sessionAnnotationFactory;
}
}
Still I am getting the following error:
Initial SessionFactory creation failed.java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
Caused By: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index; at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:936) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) at net.deldot.util.HibernateUtil.buildSessionAnnotationFactory(Unknown Source) at net.deldot.util.HibernateUtil.getSessionAnnotationFactory(Unknown Source)
I am using IntelliJ if that helps. Its not a maven project. I am not using jboss. There are no glassfish jars.I have read other answers that say this error occurs because of conflicting hibernate-jpa-2.1-api-1.0.0.final.jar and hibernate-jpa-2.0-api-1.0.0.final.jar. But I don't see hibernate-jpa-2.0 jar anywhere in my project. I don't know which jar is conflicting with hibernate-jpa-2.1 jar .How do I check that?