-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: DB2 and GENERATED ALWAYS identity column
PostPosted: Wed Oct 08, 2008 3:13 pm 
Newbie

Joined: Wed Oct 08, 2008 2:57 pm
Posts: 2
I'm having difficulty inserting a record into DB2.

The SQL Hibernate is generating shows "null" for the identity value, where I expect to see "default".

I've used SessionFactory.merge(customer) and SessionFactory.save(customer), but get the same Exception every time.


DB2 config:
Code:
CREATE TABLE TEST.CUSTOMER (
  CUSTOMER_ID   INTEGER   NOT NULL   GENERATED ALWAYS
    AS IDENTITY (START WITH 1000, INCREMENT BY 1, NO CACHE,
       NO MINVALUE, NO MAXVALUE, NO CYCLE, NO ORDER),
  CUSTOMER_NAME   VARCHAR(32)   NOT NULL,
  ADDRESS_LINE_1   VARCHAR(32),
  ADDRESS_LINE_2   VARCHAR(32),
  ADDRESS_LINE_3   VARCHAR(32),
  ADDRESS_LINE_4   VARCHAR(32),
  ADDRESS_LINE_5   VARCHAR(32),
  CITY   VARCHAR(32),
  STATE   CHARACTER(2),
  ZIP   VARCHAR(10))
  IN USERSPACE1;

ALTER TABLE TEST.CUSTOMER
  ADD CONSTRAINT CUSTOMER_PK PRIMARY KEY
    (CUSTOMER_ID);


Hibernate mapping:
Code:
   <class name="com.abc.test.model.Customer" table="test.customer">
      <id name="customerNo" column="customer_id">
         <generator class="identity"/>
      </id>
      <property name="customerName" column="customer_name" not-null="true"/>
      <property name="addressLine1" column="address_line_1"/>
      <property name="addressLine2" column="address_line_2"/>
      <property name="addressLine3" column="address_line_3"/>
      <property name="addressLine4" column="address_line_4"/>
      <property name="addressLine5" column="address_line_5"/>
      <property name="city" column="city"/>
      <property name="state" column="state"/>
      <property name="zip" column="zip"/>
   </class>


Console:
Code:
[10/8/08 13:45:25:857 CDT] 0000002a SystemOut     O [DEBUG,JDBCExceptionReporter,WebContainer : 1] could not insert: [com.abc.test.model.Customer] [insert into test.customer (customer_id,  customer_name, address_line_1, address_line_2, address_line_3, address_line_4, address_line_5, city, state, zip) values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
com.ibm.db2.jcc.b.SqlException: A value cannot be specified for column "CUSTOMER_ID" which is defined as GENERATED ALWAYS.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 11:51 am 
Newbie

Joined: Wed Oct 08, 2008 2:57 pm
Posts: 2
After double-checking my config, I found the hibernate.dialect was not set to org.hibernate.dialect.DB2Dialect.

Problem solved.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.