1
resposta

Esta dando uma exception ao executar a classe PopulaBanco.

Bom dia, eu estou quando eu executo a classe PopulaBanco, cai nessa exception:

Exception in thread "main" java.lang.IncompatibleClassChangeError: class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.loadResolverClasses(PersistenceProviderResolverHolder.java:142)
    at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader$CachingPersistenceProviderResolver.<init>(PersistenceProviderResolverHolder.java:122)
    at javax.persistence.spi.PersistenceProviderResolverHolder$PersistenceProviderResolverPerClassLoader.getPersistenceProviders(PersistenceProviderResolverHolder.java:80)
    at javax.persistence.Persistence.getProviders(Persistence.java:69)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:53)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at br.com.caelum.livraria.dao.JPAUtil.<clinit>(JPAUtil.java:10)
    at br.com.caelum.livraria.dao.PopulaBanco.main(PopulaBanco.java:25)

Segue o meu arquivo de persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">

           <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>br.com.caelum.livraria.modelo.Livro</class>
        <class>br.com.caelum.livraria.modelo.Autor</class>

        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/livrariadb" />
            <property name="javax.persistence.jdbc.user" value="postgres" />
            <property name="javax.persistence.jdbc.password" value="" />

            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        </properties>
    </persistence-unit>

</persistence>
1 resposta

Oi Hugo,

provavelmente você está usando versões incompatíveis do hibernate core e annotations.

este erro também pode ocorrer sempre que você tiver alterações incompatíveis com a biblioteca existente de várias versões da mesma classe no seu classpath. Execute o comando mvn dependency:tree e verifique se existe versões diferentes para a mesma lib no seu projeto.