Hibernate 4.1.2.FINAL Properties hbm2ddl.import_files don't seems to work

試著忘記壹切 提交于 2020-02-05 08:56:46

问题


Hi I have a issue respect a hbm2ddl.import_files, it seems that don't work and not seems to appear in the log. this is my configuration:

<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>

the hibernate.hbm2ddl.import_files=/import.sql, and the file is:

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

The 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    

The database is postgresql 9.1.1, spring 3.1.0.RELEASE and hibernate 4.1.2.Final, the hibernate.hbm2ddl.auto is set to "create", the tables and the schema create but not run sql command insert why?, I can see in the log where this command run.


回答1:


My error was the location in hibernate properties.

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

is the correct location.




回答2:


You could put import.sql in classpath(/classes/import.sql) and remove property hibernate.hbm2ddl.import_files from hibernate configuration/property.

NOTE: hibernate.hbm2ddl.auto must to create

<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>


来源:https://stackoverflow.com/questions/10392397/hibernate-4-1-2-final-properties-hbm2ddl-import-files-dont-seems-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!