-->
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: [RESOLVED] Derby and "GENERATED ALWAYS AS IDENTITY"
PostPosted: Mon Jun 05, 2006 2:25 am 
Beginner
Beginner

Joined: Mon Sep 26, 2005 8:22 am
Posts: 24
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.


Last edited by brisssou on Mon Jun 05, 2006 3:10 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 3:09 am 
Beginner
Beginner

Joined: Mon Sep 26, 2005 8:22 am
Posts: 24
ok, I smashed it up.

Looking at the DerbyDialog, it looked a bit odd... while the DB2Dialog seemed to fit a bit more.

And here we are :
Code:
Hibernate:
    insert
    into
        APP.TYPE_FLUX
        (NOM, ID)
    values
        (?, default)
Hibernate:
   
values
    identity_val_local()


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.