I searched the forum and googled with no success. So I'm posting here.
Here is the problem : I can't use Derby's identity column, Hibernate keeps trying to set the id, where I expect it to let the DB define it
Hibernate version:
3.1.3
Mapping documents:
Code:
<hibernate-mapping>
<class name="fr.cnaf.trafic.model.TypeFlux" table="TYPE_FLUX">
<comment></comment>
<id name="id" type="int" column="ID">
<generator class="assigned" />
</id>
<property name="nom" type="string" column="NOM" length="20"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
TypeFlux tf = new TypeFlux();
tf.setNom("essaiJava");
session().save(tf);
Full stack trace of any exception that occurs:Code:
2006-06-05 07:51:10,756 : JDBCExceptionReporter.logExceptions : SQL Error: -1, SQLState: 42Z23
2006-06-05 07:51:10,928 : JDBCExceptionReporter.logExceptions : Attempt to modify an identity column 'ID'.
2006-06-05 07:51:10,943 : AbstractFlushingEventListener.performExecutions : Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [fr.cnaf.trafic.model.TypeFlux]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2078)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
(...)
Caused by: org.apache.derby.client.am.SqlException: Attempt to modify an identity column 'ID'.
at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source)
at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source)
at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:93)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
(...)
The generated SQL (show_sql=true):Code:
insert
into
APP.TYPE_FLUX
(NOM, ID)
values
(?, ?)
where I would like
Code:
insert
into
APP.TYPE_FLUX
(NOM)
values
(?)
Thank for any help !!
Brice.