Hi,
I have the following simple class:
public class Contractor {
private long id;
private String name;
public Contractor(){
}
public Contractor(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
And the mapping for it :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="ibm.request">
<class name="Contractor" table="C_DB">
<id
name="id"
column="C_DB_ID">
<generator class="native"/>
</id>
<property
name="name"
column="name">
</property>
</class>
</hibernate-mapping>
Table:
CREATE TABLE C_BD (
C_DB_ID BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 32672 NO CYCLE CACHE 17),
name VARCHAR(500)
)
DATA CAPTURE NONE ;
ALTER TABLE C_BD ADD CONSTRAINT Contr_BD_PK PRIMARY KEY (C_DB_ID);
And the testing code:
SessionFactory factory = config.buildSessionFactory();
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
Contractor c = new Contractor();
c.setName("some contractor");
session.save(c);
tx.commit();
session.flush();
All looks very simple but this is what i get:
.17:45:26,408 INFO Environment:514 - Hibernate 3.2.6
17:45:26,428 INFO Environment:547 - hibernate.properties not found
17:45:26,439 INFO Environment:681 - Bytecode provider name : cglib
17:45:26,449 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
17:45:26,549 INFO Configuration:559 - Reading mappings from resource : ibm/request/RequestRecordLine.hbm.xml
17:45:26,949 INFO HbmBinder:300 - Mapping class: ibm.request.RequestRecordLine -> RRL
17:45:27,039 INFO Configuration:559 - Reading mappings from resource : ibm/request/RequestRecord.hbm.xml
17:45:27,109 INFO HbmBinder:300 - Mapping class: ibm.request.RequestRecord -> RR
17:45:27,109 INFO Configuration:559 - Reading mappings from resource : ibm/request/Contractors.hbm.xml
17:45:27,130 INFO HbmBinder:300 - Mapping class: ibm.request.Contractors -> CONTRACTORS
17:45:27,140 INFO Configuration:559 - Reading mappings from resource : ibm/request/Contractor.hbm.xml
17:45:27,160 INFO HbmBinder:300 - Mapping class: ibm.request.Contractor -> C_DB
17:45:27,160 INFO HbmBinder:2382 - Mapping collection: ibm.request.RequestRecordLine.contractors -> CONTRACTORS
17:45:27,160 INFO HbmBinder:2382 - Mapping collection: ibm.request.RequestRecord.rrlList -> RRL
17:45:27,200 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
17:45:27,200 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
17:45:27,200 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
17:45:27,340 INFO DriverManagerConnectionProvider:80 - using driver: com.ibm.db2.jcc.DB2Driver at URL: jdbc:db2://9.157.146.107:50000/CRM_GPSG
17:45:27,340 INFO DriverManagerConnectionProvider:86 - connection properties: {user=db2admin, password=****}
17:45:27,610 INFO SettingsFactory:89 - RDBMS: DB2/NT, version: SQL08028
17:45:27,610 INFO SettingsFactory:90 - JDBC driver: IBM DB2 JDBC Universal Driver Architecture, version: 3.50.152
17:45:27,650 INFO Dialect:152 - Using dialect: org.hibernate.dialect.DB2Dialect
17:45:27,660 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
17:45:27,670 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
17:45:27,670 INFO SettingsFactory:143 - Automatic flush during beforeCompletion(): disabled
17:45:27,670 INFO SettingsFactory:147 - Automatic session close at end of transaction: disabled
17:45:27,670 INFO SettingsFactory:162 - Scrollable result sets: enabled
17:45:27,670 INFO SettingsFactory:170 - JDBC3 getGeneratedKeys(): enabled
17:45:27,670 INFO SettingsFactory:178 - Connection release mode: auto
17:45:27,670 INFO SettingsFactory:205 - Default batch fetch size: 1
17:45:27,680 INFO SettingsFactory:209 - Generate SQL with comments: disabled
17:45:27,680 INFO SettingsFactory:213 - Order SQL updates by primary key: disabled
17:45:27,680 INFO SettingsFactory:217 - Order SQL inserts for batching: disabled
17:45:27,680 INFO SettingsFactory:386 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
17:45:27,690 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory
17:45:27,690 INFO SettingsFactory:225 - Query language substitutions: {}
17:45:27,690 INFO SettingsFactory:230 - JPA-QL strict compliance: disabled
17:45:27,690 INFO SettingsFactory:235 - Second-level cache: enabled
17:45:27,690 INFO SettingsFactory:239 - Query cache: disabled
17:45:27,690 INFO SettingsFactory:373 - Cache provider: org.hibernate.cache.NoCacheProvider
17:45:27,690 INFO SettingsFactory:254 - Optimize cache for minimal puts: disabled
17:45:27,690 INFO SettingsFactory:263 - Structured second-level cache entries: disabled
17:45:27,700 INFO SettingsFactory:290 - Statistics: disabled
17:45:27,700 INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
17:45:27,700 INFO SettingsFactory:309 - Default entity-mode: pojo
17:45:27,700 INFO SettingsFactory:313 - Named query checking : enabled
17:45:27,740 INFO SessionFactoryImpl:161 - building session factory
17:45:28,301 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
17:45:28,461 WARN JDBCExceptionReporter:77 - SQL Error: -204, SQLState: 42704
17:45:28,461 ERROR JDBCExceptionReporter:78 - DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.C_DB, DRIVER=3.50.152
17:45:28,461 WARN JDBCExceptionReporter:77 - SQL Error: -727, SQLState: 56098
17:45:28,471 ERROR JDBCExceptionReporter:78 - DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-204;42704;DB2ADMIN.C_DB, DRIVER=3.50.152
17:45:28,471 WARN JDBCExceptionReporter:77 - SQL Error: -727, SQLState: 56098
17:45:28,471 ERROR JDBCExceptionReporter:78 - DB2 SQL Error: SQLCODE=-727, SQLSTATE=56098, SQLERRMC=2;-204;42704;DB2ADMIN.C_DB, DRIVER=3.50.152
E
Time: 2.313
There was 1 error:
1) testSaveRecord(ibm.request.test.DBRelationsTest)org.hibernate.exception.SQLGrammarException: could not insert: [ibm.request.Contractor]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2163)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2643)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at ibm.request.test.DBRelationsTest.testSaveRecord(DBRelationsTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at ibm.request.test.DBRelationsTest.main(DBRelationsTest.java:51)
Caused by: com.ibm.db2.jcc.b.nm: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.C_DB, DRIVER=3.50.152
at com.ibm.db2.jcc.b.wc.a(wc.java:579)
at com.ibm.db2.jcc.b.wc.a(wc.java:57)
at com.ibm.db2.jcc.b.wc.a(wc.java:126)
at com.ibm.db2.jcc.b.tk.c(tk.java:1901)
at com.ibm.db2.jcc.b.tk.d(tk.java:1889)
at com.ibm.db2.jcc.b.tk.a(tk.java:1416)
at com.ibm.db2.jcc.t4.db.g(db.java:138)
at com.ibm.db2.jcc.t4.db.a(db.java:38)
at com.ibm.db2.jcc.t4.t.a(t.java:32)
at com.ibm.db2.jcc.t4.sb.h(sb.java:141)
at com.ibm.db2.jcc.b.tk.N(tk.java:1387)
at com.ibm.db2.jcc.b.uk.Kb(uk.java:2461)
at com.ibm.db2.jcc.b.uk.e(uk.java:3101)
at com.ibm.db2.jcc.b.uk.zb(uk.java:568)
at com.ibm.db2.jcc.b.uk.executeUpdate(uk.java:551)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
... 33 more
How can i fix it?
Hibernate version:3.2
Name and version of the database you are using:DB2
|