1

嗨,我有一个关于 hbm2ddl.import_files 的问题,它似乎不起作用并且似乎没有出现在日志中。这是我的配置:

<property name="hibernateProperties">
        <value>
            hibernate.dialect=${hibernate.dialect}
            hibernate.default_schema=${hibernate.default_schema}
            hibernate.jdbc.batch_size=${hibernate.jdbc.batch_size}
            hibernate.show_sql=${hibernate.show_sql}
            hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
            hibernate.id.new_generator_mappings=${hibernate.id.new_generator_mappings}
            hibernate.hbm2ddl.import_files=${hibernate.hbm2ddl.import_files}
            <!-- Auto Generated Schemas and tables not good for production
            hibernate.hbm2ddl.auto=update-->
         </value>
    </property>

hibernate.hbm2ddl.import_files=/import.sql,文件为:

insert into DEPARTAMENTO (NOMBRE_DEPART,REFERENCIA_DEPART) values ('AMAZONAS')

jdbc.properties:

#org.hibernate.dialect.PostgreSQLDialect
hibernate.default_schema = "DBMERCANCIAS"
hibernate.show_sql = true
hibernate.id.new_generator_mappings = true
hibernate.hbm2ddl.auto = create
hibernate.jdbc.batch_size = 5
#Default the factory to use to instantiate transactions     org.transaction.JDBCTransactionFactory
hibernate.transaction.factory_class=org.transaction.JDBCTransactionFactory
#Initialize values statements only on create-drop or create
hibernate.hbm2ddl.import_files = /import.sql    

数据库是postgresql 9.1.1,spring 3.1.0.RELEASE和hibernate 4.1.2.Final,hibernate.hbm2ddl.auto设置为“create”,表和schema创建但不运行sql命令插入为什么?,我可以在运行此命令的日志中看到。

4

2 回答 2

4

我的错误是休眠属性中的位置。

hibernate.hbm2ddl.import_files = /META-INF/spring/import.sql

是正确的位置。

于 2012-06-13T01:58:29.483 回答
0

您可以从休眠配置/属性import.sql中放入classpath(/classes/import.sql)和删除属性。hibernate.hbm2ddl.import_files

注意: hibernate.hbm2ddl.auto 必须创建

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
    </property>
</bean>
于 2015-07-14T13:31:28.820 回答