Hibernate is not mapping classes

Asked

Viewed 214 times

0

The Hibernate I am using is not generating the tables automatically

My Persistence.xml file

<?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="WebServiceRest" transaction-type="RESOURCE_LOCAL">

        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>br.com.model.Departamento</class>

        <properties>
            <!-- Url do banco Mysql  -->
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/william" />
            <!-- Driver Conector JDBC do Mysql -->
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            <!-- Usuário do banco -->
            <property name="hibernate.connection.username" value="root" />
            <!-- Senha do banco -->
            <property name="hibernate.connection.password" value="root" />
            <!-- Mapeia todas a classes com anotações  -->
            <property name="hibernate.archive.autodetection" value="class" />
            <!-- Debuga as querys do Sql -->
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="hbm2ddl.auto" value="update" />
        </properties>

    </persistence-unit>
</persistence>

My Class with the Notes

package br.com.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;
import javax.persistence.Id;

@Entity
@Table(name="departamento")
public class Departamento {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private int Id;

    @Column(name="nome")
    private String Nome;

    public int getId() {
        return Id;
    }

    public void setId(int id) {
        Id = id;
    }

    public String getNome() {
        return Nome;
    }

    public void setNome(String nome) {
        Nome = nome;
    }



}

My web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>WebServiceRest</display-name>


    <servlet>

        <servlet-name>Jersey Rest</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>br.com.resources</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>
        <servlet-name>Jersey Rest</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>


</web-app>

And these are the libs I’m using:

 antlr-2.7.7.jar
    asm-1.3.3.jar
    cdi-api-1.1-PFD.jar
    classmate-1.3.0.jar
    dom4j-1.6.1.jar
    el-api-2.2.jar
    geronimo-jta_1.1_spec-1.1.1.jar
    hibernate-commons-annotations-5.0.1.Final.jar
    hibernate-core-5.2.0.Final.jar
    hibernate-jpa-2.1-api-1.0.0.Final.jar
    jackson-core-asl-1.9.2.jar
    jackson-jaxrs-1.9.2.jar
    jackson-mapper-asl-1.9.2.jar
    jackson-xc-1.9.2.jar
    jandex-2.0.0.Final.jar
    javassist-3.20.0-GA.jar
    javassist.jar
    javax.inject-1.jar
    jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar
    jboss-logging-3.3.0.Final.jar
    jersey-apache-client-1.19.1.jar
    jersey-atom-abdera-1.19.1.jar
    jersey-client-1.19.1.jar
    jersey-core-1.19.1.jar
    jersey-guice-1.19.1.jar
    jersey-json-1.19.1.jar
    jersey-multipart-1.19.1.jar
    jersey-server-1.19.1.jar
    jersey-servlet-1.19.1.jar
    jersey-simple-server-1.19.1.jar
    jersey-spring-1.19.1.jar
    jettison-1.1.jar
    jsr250-api-1.0.jar
    jsr311-api-1.1.1.jar
    jta-1_1.jar
    lucene-core-5.5.4.jar
    lucene-queryparser-5.5.4.jar
    mysql-connector-java-5.1.45-bin.jar
    oauth-client-1.19.1.jar
    oauth-server-1.19.1.jar
    oauth-signature-1.19.1.jar
    xml-apis-1.0.b2.jar
    xml-apis-1.3.03.jar

Obs I’m not using Maven

2 answers

1

  • Yes, I followed step by step but still without automatic mapping.

    1. you have already created the bank on your localhost? 2. how is it appearing on the console? msg error or q? can be made available here?

1


Friend try to change the following property

<property name="hbm2ddl.auto" value="update" /> 

for

<property name="hibernate.hbm2ddl.auto" value="create"/>
  • Vlw, it worked perfect, it was exactly what was wrong.

Browser other questions tagged

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