Hibernate does not create tables in spite of hibernate.hbm2ddl.auto=create

你离开我真会死。 提交于 2019-12-11 11:07:08

问题


I 've tried several editions but NOT use. I need to resolve this part to continue the project .
The hibernate is not generating the tables in the database, I can not find where the error is.

The code is:

    package br.com.evolutionary.modelo;

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

@Entity
public class Pokemon {

    @Id
    @GeneratedValue
    private Long id;

    @Column
    private String nome;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

}

The persistence is:

<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="evolutionary"
    transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/evolutionary" />
        <property name="hibernate.connection.driver" value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.username" value="root" />
        <property name="hibernate.connection.password" value="12345" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
    </properties>
</persistence-unit>

The pom.xml is:

<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>br.com</groupId>
    <artifactId>evolutionary</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>6.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

The output log tomcat is:

mai 12, 2016 7:30:03 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:evolutionary' did not find a matching property.
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server version:        Apache Tomcat/8.0.33
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server built:          Mar 18 2016 20:31:49 UTC
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server number:         8.0.33.0
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Name:               Linux
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Version:            4.4.0-21-generic
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Architecture:          amd64
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Version:           1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Vendor:            Oracle Corporation
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_BASE:         /home/douglas/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_HOME:         /opt/apache-tomcat-8.0.33
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.base=/home/douglas/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.home=/opt/apache-tomcat-8.0.33
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dwtp.deploy=/home/douglas/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Djava.endorsed.dirs=/opt/apache-tomcat-8.0.33/endorsed
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dfile.encoding=UTF-8
mai 12, 2016 7:30:03 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAÇÕES: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
mai 12, 2016 7:30:03 AM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["http-nio-8080"]
mai 12, 2016 7:30:03 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
mai 12, 2016 7:30:03 AM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["ajp-nio-8009"]
mai 12, 2016 7:30:03 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
mai 12, 2016 7:30:03 AM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 623 ms
mai 12, 2016 7:30:03 AM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service Catalina
mai 12, 2016 7:30:03 AM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/8.0.33
mai 12, 2016 7:30:06 AM org.apache.jasper.servlet.TldScanner scanJars
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
mai 12, 2016 7:30:06 AM com.sun.faces.config.ConfigureListener contextInitialized
INFORMAÇÕES: Inicializando Mojarra 2.2.13 ( 20160203-1910 unable to get svn info) para o contexto '/evolutionary'
mai 12, 2016 7:30:06 AM com.sun.faces.spi.InjectionProviderFactory createInstance
INFORMAÇÕES: JSF1048: Anotações PostConstruct/PreDestroy presentes.  Os métodos ManagedBeans marcados com essas anotações informarão as anotações processadas.
mai 12, 2016 7:30:07 AM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
INFORMAÇÕES: Running on PrimeFaces 5.3
mai 12, 2016 7:30:07 AM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-nio-8080"]
mai 12, 2016 7:30:07 AM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-nio-8009"]
mai 12, 2016 7:30:07 AM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 4132 ms

Can anyone help?


回答1:


Check if persistence.xml is residing in the Meta-INF folder.

In thsi case I guess, Persistence.xml is not getting loaded on the application startup.

Also check whether you are calling Persistence.createEntityManagerFactory(persistantUnitName) in your code.

Please take a look at Hibernate EntityManager documentation below for getting idea on configuration and bootstrapping :

https://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/configuration.html



来源:https://stackoverflow.com/questions/37191430/hibernate-does-not-create-tables-in-spite-of-hibernate-hbm2ddl-auto-create

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!