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.