0

Currently refreshing my JPA and Hibernate Know-How, I am writing some example code in the form of a todo list swing application.

This is the minimal example that reproduces my problem:

public static void main(String[] args) {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("SwingTodoPU");
}

This is the stacktrace I get when running the application (I am using Netbeans' default build configuration and no additional build tools like Maven):

Okt 09, 2015 12:10:21 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Okt 09, 2015 12:10:21 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Okt 09, 2015 12:10:21 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/jandex/IndexView
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:129)
    at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:93)
    at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:86)
    at org.hibernate.ejb.HibernatePersistence.getEntityManagerFactoryBuilderOrNull(HibernatePersistence.java:101)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:67)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at at.swingtodo.SwingTodo.main(SwingTodo.java:39)
Caused by: java.lang.ClassNotFoundException: org.jboss.jandex.IndexView
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 10 more
Java Result: 1

The persistence unit is configured in src/META-INF/persistence.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="SwingTodoPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>at.swingtodo.entities.Item</class>
    <shared-cache-mode>NONE</shared-cache-mode>
    <validation-mode>NONE</validation-mode>
    <properties>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tododb?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.password" value="tododb"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="tododb"/>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
    </properties>
  </persistence-unit>
</persistence>

hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/tododb?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">tododb</property>
    <property name="hibernate.connection.password">tododb</property>
  </session-factory>
</hibernate-configuration>

I understand that Hibernate is trying to use Jandex but I do not understand why it is, even in my minimal example. As you can see, I am not using metadata generation as the OP in this related question "Why is hibernate 4.2 using jandex and classmate [...]". I have also been unable to resolve the warnings that are output before the Exception is thrown (my code is not referencing org.hibernate.ejb.HibernatePersistence)

If possible, I would like to avoid the obvious workaround of satisfying Jandex and its dependencies.

I am using Hibernate 4.3, JPA 2.1, JDK 1.7, and NetBeans 8.0.2.

Community
  • 1
  • 1
Michael Jaros
  • 4,586
  • 1
  • 22
  • 39
  • 1
    I "solved" this by creating a maven project and importing my code. Maven pulled in the additional dependencies. But I'm still interested in how loading of Jandex & Co. can be prevented in the first place. – Michael Jaros Oct 12 '15 at 09:08
  • Did you fix finally fix this? I'm having the same issue right now on Spring 4.0.6 hosted on JBoss 7.2. I'm quite reluctant to bundle Jandex to my lib directory. This is my last resort. Thanks! – Charles Morin Apr 22 '16 at 13:29
  • 1
    @CharlesMorin: No, sorry. This was part of some know-how building for a project I would have worked on, but when that project was cancelled, I did not continue to pursue this topic. – Michael Jaros Apr 24 '16 at 16:44

0 Answers0