2017-01-26 53 views
2

我正在嘗試使用Hibernate和JtOpen在iSeries(V7R1)中連接到DB2。我遵循Hibernate文檔並創建了以下內容。當我連接到DB2時,它與HSQLDB協同工作,我面臨着下面的錯誤。Hibernate DB2身份生成錯誤

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) 

Hibernate配置:

<!-- 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)。

回答

2

我發現可能的解決方法是解決我的問題。

設置hbm2ddl.auto創建而不是更新解決了問題。首先執行創建創建架構,然後我刪除屬性,它現在工作正常。

因爲我們只使用現有的表格並在應用程序中使用之前創建新表格,所以適用於我。