Sekar
Sekar

Reputation: 387

Hibernate DB2 Identity Generation Error

I am trying to connect to DB2 in iSeries(V7R1) using Hibernate and JtOpen. I followed Hibernate documentation and created the following. It works with HSQLDB when i connect to DB2 i am facing the below error.

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

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

Resource Configuration:

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

I tried creating the table first and connecting. Then too i am facing the same issue. I tried changing the generator to native, sequence and identity. How can i ensure that hibernate is connecting to the Library(Schema) is specify.

Upvotes: 2

Views: 1209

Answers (1)

Sekar
Sekar

Reputation: 387

I found possible work around for my problem, though not a solution.

Setting the hbm2ddl.auto to create instead of update solved the issue. First executed with the create to create the schema, then i removed the property and it works fine now.

Since we only use existing tables and create new tables before using in application this works for me.

Upvotes: 2

Related Questions