1

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.

Vodo-Siosk Baas
  • 183
  • 3
  • 12
  • 27

2 Answers2

4

My error was the location in hibernate properties.

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

is the correct location.

Vodo-Siosk Baas
  • 183
  • 3
  • 12
  • 27
0

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>
Ravi Parekh
  • 5,253
  • 9
  • 46
  • 58