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    

データベースはpostgresql9.1.1、spring 3.1.0.RELEASE、hibernate 4.1.2.Finalで、hibernate.hbm2ddl.autoは「create」に設定され、テーブルとスキーマは作成しますが、sqlコマンドを実行しません。このコマンドが実行された場所をログで確認できます。

4

2 に答える 2

4

私のエラーは、休止状態のプロパティ内の場所でした。

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

正しい場所です。

于 2012-06-13T01:58:29.483 に答える
0

休止状態の構成/プロパティにプロパティを追加import.sqlclasspath(/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 に答える