Hibernate / JPA在启动时未对DB模式进行验证

时间:2011-09-15 23:20:23

标签: java hibernate jpa jpa-2.0 guice-persist

由于某些原因,hibernate没有捕获将实体映射到不存在的表等问题。我的persistence.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_1_0.xsd" version="1.0">

    <!-- A JPA Persistence Unit -->
    <persistence-unit name="printLogixJpaUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.printlogix.rp.server.domain.User</class>
        <class>com.printlogix.rp.server.domain.UserImage</class>
        <class>com.printlogix.rp.server.domain.TemplateInstance</class>
        <class>com.printlogix.rp.server.domain.UserOrder</class>
        <class>com.printlogix.rp.server.domain.OrderLineItem</class>
        <class>com.printlogix.rp.server.domain.OrderStatus</class>
        <class>com.printlogix.rp.server.domain.AgencyImage</class>
        <class>com.printlogix.rp.server.domain.Agency</class>
        <class>com.printlogix.rp.server.domain.Brokerage</class>
        <class>com.printlogix.rp.server.domain.SystemTemplate</class>
        <class>com.printlogix.rp.server.domain.TemplateType</class>
        <class>com.printlogix.rp.server.domain.Product</class>
        <class>com.printlogix.rp.server.domain.ProductDefinition</class>
        <class>com.printlogix.rp.server.domain.ExpeditedAddress</class>
        <class>com.printlogix.rp.server.domain.BrokerageUser</class>
        <class>com.printlogix.rp.server.domain.StateProvince</class>
        <class>com.printlogix.rp.server.domain.Country</class>
        <class>com.printlogix.rp.server.domain.AwardClub</class>
        <class>com.printlogix.rp.server.domain.SuperUser</class>
        <class>com.printlogix.rp.server.domain.AgencyUser</class>
        <class>com.printlogix.rp.server.domain.RememberMe</class>
        <class>com.printlogix.rp.server.domain.PasswordResetRequest</class>
        <class>com.printlogix.rp.server.domain.SystemTheme</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>

        <properties>
            <property name="hibernate.show_sql" value="true"/>
            <!--Begin Credentials -->
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost/realtorprint_dev?autoReconnect=true"/>
            <property name="hibernate.connection.username" value="test"/>
            <property name="hibernate.connection.password" value="test"/>
            <!--End Credentials -->
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
        </properties>
    </persistence-unit>

</persistence>

1 个答案:

答案 0 :(得分:10)

尝试添加属性“hibernate.hbm2ddl.auto”,其值为“validate”:

<property name="hibernate.hbm2ddl.auto" value="validate"/>