0
votes

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?

2

2 Answers

1
votes

You are using hibernate-commons-annotations-5.0.1.Final.jar from Hibernate 5 with hibernate-core-4.3.5.Final.jar from Hibernate 4. It is incorrect.

@Table annotation with Table#indexes() method should be in the hibernate-jpa-2.1-api-1.0.0.Final.jar

https://stackoverflow.com/a/35569978/3405171

You can try to check where the old @Table annotation comes from using this approach

https://stackoverflow.com/a/37409315/3405171

And, please, use Maven or Gradle.

0
votes

Okay, not the best solution but a workaround. Since I was unable to enable weblogic's support for JPA2.1, I replaced Hibernate-core-4.3.5.Final.jar with Hibernate-core-4.2.21.Final.jar (JPA2.1 support was introduced in Hibernate 4.3.0). Not getting that error anymore.