Hibernate DB2身份生成错误

时间:2017-01-26 13:16:25

标签: hibernate db2-400

我正在尝试使用Hibernate和JtOpen连接到iSeries(V7R1)中的DB2。我按照Hibernate文档创建了以下内容。当我连接到DB2时,它与HSQLDB一起工作,我面临以下错误。

WARN: SQL Error: -204, SQLState: 42704
Jan 27, 2017 1:40:25 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: [SQL0204] SYSSEQUENCES in SYSIBM type *FILE not found.
Jan 27, 2017 1:40:26 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:as400://harainbw:446/rajarra]
Initial Session Factory creation failed. org.hibernate.exception.SQLGrammarException: Unable to build DatabaseInformation
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.repsrv.infopro.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:14)
    at com.repsrv.infopro.util.HibernateUtil.<clinit>(HibernateUtil.java:7)
    at com.repsrv.infopro.EventManager.createAndStoreEvent(EventManager.java:19)
    at com.repsrv.infopro.EventManager.main(EventManager.java:14)

休眠配置:     

    <!-- Database connection settings -->
    <property name="connection.driver_class">com.ibm.as400.access.AS400JDBCDriver</property>
    <property name="connection.url">jdbc:as400://myserver:446</property>
    <property name="connection.username">uuuuu</property>
    <property name="connection.password">xxxxx</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.DB2400Dialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <property name="hbm2ddl.auto">update</property>

    <mapping resource="com/repsrv/infopro/domain/Event.hbm.xml" />

</session-factory>

资源配置:

<class name="Event" table="EVENT" schema="mylib">
    <id name="id" column="EVENT_ID">
        <generator class="sequence" />
    </id>
    <property name="date" type="timestamp" column="EVENT_DATE" />
    <property name="title"/>
</class>

我尝试先创建表并连接。然后我也面临同样的问题。我尝试将生成器更改为本机,序列和标识。我如何确保hibernate连接到库(Schema)是指定的。

1 个答案:

答案 0 :(得分:2)

我找到了解决问题的方法,但不是解决方法。

将hbm2ddl.auto设置为create而不是update解决了这个问题。首先使用create执行创建模式,然后我删除了属性,它现在工作正常。

由于我们在使用应用程序之前只使用现有表并创建新表,因此这对我有用。