Hibernate does not recognize class annotation

Asked

Viewed 2,919 times

0

I have a Maven project, with Glassfish 4.0, Hibernate, I am using annotations and my project was faceted with JPA the persistence.xml file was generated and the Glassfish Connection pool is working. however the following message is generated by the Eclipse Inspector:

Class "com.financeiro.Pessoa" is Managed, but is not Listed in the persistence.xml file

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
    xmlns="http://xmlns.jcp.org/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="Finaceiro" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/MavenDB</jta-data-source>
        <properties>
            <property name="hibernate.transaction.jta.platform"
                value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        </properties>
    </persistence-unit>
</persistence>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.financeiro</groupId>
    <artifactId>Finaceiro</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- Dependências do Projeto -->

    <dependencies>

        <!-- Servlets API -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Núcleo do Hibernate -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.8.Final</version>
            <scope>compile</scope>
        </dependency>

        <!-- Implementação de EntityManager da JPA -->

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.8.Final</version>
            <scope>compile</scope>
        </dependency>

        <!-- Driver JDBC do MySQL -->

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>

How am I using annotations is it necessary to map the class in persistence.xml or is the error generated for another reason ? I wonder if anyone has the solution.

1 answer

2


You must add the class com.financeiro.Pessoa in his persistence.xml.

Place the following line before the line it contains <properties>:

<class>com.financeiro.Pessoa</class>

An alternative, which is not officially supported by the JPA specification, but works in Hibernate, is to add the following property:

<property name="hibernate.archive.autodetection" value="class, hbm"/>
  • Perfect error stopped occurring however even then the database tables are not being generated

  • The estate exclude-unlisted-classes is of the JPA specification and does the service.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.