Hibernate 4没有创建表

时间:2012-04-28 20:10:02

标签: java spring-3 mysql5 hibernate-4.x

我正在使用MySQL5,而我的applicationContext.xml包含以下bean:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/ems" />
    <property name="username" value="root" />
    <property name="password" value="admin" />
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hbm2ddl.auto">create</prop>
            <prop key="connection.url">jdbc:mysql://localhost:3306/ems</prop>
            <prop key="connection.username">root</prop>
            <prop key="connection.password">admin</prop>
            <prop key="connection.driver_class">com.mysql.jdbc.Driver</prop>
        </props>
    </property>
    <property name="mappingDirectoryLocations" value="/WEB-INF/resources/mappings" />
</bean>

我使用MySQL Workbench创建了一个名为“ems”的模式,但是当我在控制台中部署应用程序时,它会打印:

01:22:54,823 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000206: hibernate.properties not found
01:22:54,827 INFO  [org.hibernate.cfg.Environment] (MSC service thread 1-2) HHH000021: Bytecode provider name : javassist
01:22:54,841 INFO  [org.hibernate.cfg.Configuration] (MSC service thread 1-2) HHH000220: Reading mappings from file: C:\Development\JBoss-AS-7.1.0.Final\standalone\tmp\vfs\tempf3cbb10675b49730\EMSApplication.war-43fc183fcacfc03f\WEB-INF\resources\mappings\User.hbm.xml
01:22:56,884 INFO  [org.hibernate.dialect.Dialect] (MSC service thread 1-2) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
01:22:56,892 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-2) HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
01:22:56,901 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-2) HHH000399: Using default transaction strategy (direct JDBC transactions)
01:22:56,908 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-2) HHH000397: Using ASTQueryTranslatorFactory

控制台中没有异常。但是在模式ems中,表是空的,这意味着没有创建表。

User.hbm.xml位于指定位置,该位置为:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="app.dev.ems.data.model.User" table="USER">
        <id name="id" column="ID">
            <generator class="native"/>         
        </id>
    </class>
</hibernate-mapping>

User.java也存在。

我正在使用带有spring-orm-3.1.1.RELEASE的hibernate-core-4.1.1.Final。

我做错了什么?

1 个答案:

答案 0 :(得分:4)

我犯了一个错误: <prop key="hbm2ddl.auto">create</prop>应为<prop key="hibernate.hbm2ddl.auto">create</prop>