尽管设置了hibernate.hbm2ddl.auto = create,Hibernate仍未创建表 [英] Hibernate does not create tables in spite of hibernate.hbm2ddl.auto=create

查看:87
本文介绍了尽管设置了hibernate.hbm2ddl.auto = create,Hibernate仍未创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了多个版本,但没有使用.我需要解决这一部分才能继续进行该项目.
休眠状态无法在数据库中生成表,我找不到错误在哪里.

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.

代码是:

    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;
    }

}

持久性是:

<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>

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>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>

tomcat的输出日志为:

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

任何人都可以帮忙吗?

推荐答案

检查persistence.xml是否驻留在Meta-INF文件夹中.

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

在这种情况下,我猜想Persistence.xml不会在应用程序启动时加载.

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

还要检查您是否在代码中调用了 Persistence.createEntityManagerFactory(persistantUnitName).

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

请查看下面的Hibernate EntityManager文档,以获取有关配置和引导的想法:

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

这篇关于尽管设置了hibernate.hbm2ddl.auto = create,Hibernate仍未创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆