在Hibernate Mapping中检查未映射的列

时间:2014-03-23 02:10:00

标签: java database hibernate

我正在为现有数据库编写数据库同步工具。其中一个要求是使用数据库模式验证实体。程序必须知道任何数据库更改(例如向数据库添加新列)。我计划在这个项目中使用Hibernate。

无论如何,Hibernate可以验证数据库中实体和表之间的区别吗?

Hibernate可以输出SQL脚本,以便我可以在运行它之前查看SQL脚本来更新目标数据库吗?

1 个答案:

答案 0 :(得分:0)

是的,hibernate可以在日志中输出SQL。 您需要设置: - <property name="hibernate.show_sql" value="true"/>

但服务器生成的SQL有点乱,因此您必须根据数据库表修改列名。

请使用hibernate

查看我的项目的以下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="communityPortalPersitenceUnit">
        <class>com.googlecode.frameworksintegration.domain.Blog</class>
        <properties>
             <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/conhint_prod" />  

        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />

             <property name="hibernate.connection.username" value="root" /> 
            <property name="hibernate.connection.password" value="admin" /> 



            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
            <property name="hibernate.connection.zeroDateTimeBehavior" value="convertToNull"/>
            <property name="hibernate.show_sql" value="true"/>
            <!--Start :- connection pooling -->
            <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />

            <property name="hibernate.c3p0.max_size" value="100" />
            <property name="hibernate.c3p0.min_size" value="0" />
            <property name="hibernate.c3p0.acquire_increment" value="1" />
            <property name="hibernate.c3p0.idle_test_period" value="300" />
            <property name="hibernate.c3p0.max_statements" value="0" />
            <property name="hibernate.c3p0.timeout" value="100" />
            <!--End :- connection pooling -->


        </properties>

    </persistence-unit>
</persistence>