Hibernate/JPA not validating against DB schema on startup
Asked Answered
M

1

3

For some reason hibernate is not catching issues like mapping entities to tables that do not exist. My persistence.xml file looks like this...

<?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>
Montelongo answered 15/9, 2011 at 23:20 Comment(0)
R
10

Try adding the property "hibernate.hbm2ddl.auto" with value of "validate":

<property name="hibernate.hbm2ddl.auto" value="validate"/>
Runesmith answered 15/9, 2011 at 23:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.