休眠。hbm2ddl.auto 它不工作

hibernate.hbm2ddl.auto its not working

我创建了一个 EJB 项目并使用实体管理器(配置:数据源和 persitence.xml) 如何添加休眠。hbm2ddl.auto 属性? 我将此 属性 添加到 persitence.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="UniQPersistence" transaction-type="JTA">

             <jta-data-source>java:jboss/datasources/DefaultDS</jta-data-source>

             <properties>
              <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/uniqdba" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
             <property name="hibernate.hbm2.auto" value="update"/>
             <property name="hibernate.show_sql" value="true"/>
             <property name="hibernate.c3p0.timeout" value="500"/>
             </properties>


            </persistence-unit> 

             </persistence>

Standalone.xml

<datasource jta="true" jndi-name="java:jboss/datasources/DefaultDS" pool-name="DefaultDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:mysql://localhost:3306/uniqdba</connection-url>
                    <driver>mysqlDriver</driver>
                    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                    <security>
                        <user-name>root</user-name>
                        <password>root</password>
                    </security>
                </datasource>

你的代码是正确的,除了一个错误,将 hbm2 替换为 hbm2ddl。 代码应该像

        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.c3p0.timeout" value="500"/>
         </properties>