-->
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: Attempt to modify identity column IDUSER
PostPosted: Sun Jan 30, 2011 6:37 pm 
Beginner
Beginner

Joined: Sun Jan 30, 2011 8:14 am
Posts: 24
Hi guys,
I've encountered an issue using hibernate with derby database and it seems no solution on internet is present, like it was a bug.
I've a table in the db in which I've an autoincrement id

Code:
create table USER
(
   IDUSER           Int NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
   NAME              varchar(100)
)


this syntax should be correct, cause if I add a insert like "insert into user(NAME) values('John')" it works correctly, autoincrementing id.
If I try an insert with hibernate I've this error:

Code:
GRAVE: Attempt to modify identity column 'IDUSER'.
30-gen-2011 23.24.29 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
GRAVE: Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [app.entity.User]


Code:
<hibernate-mapping>
   <class name="app.entity.User" table="USER" schema="ROOT">
        <id name="idUser" column="IDUSER" type="long">
            <generator class="increment" />
         </id>
        <property name="name" type="string">
            <column name="NAME" length="100" />
        </property>
</class>
</hibernate-mapping>


This is save method
Code:
User user = new User();
user.setName("John");
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();


this is part of configuration file
Code:
<session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
    <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
    <property name="hibernate.connection.url">jdbc:derby://localhost:1527/xxxx</property>
    <property name="hibernate.connection.username">yyyy</property>
    <property name="hibernate.connection.password">zzzz</property>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <mapping resource="app/entity/User.hbm.xml"/>
  </session-factory>


I Hope someone cal help me, I can't go on, I think to give up with derby... :(
Please help me


Top
 Profile  
 
 Post subject: Re: Attempt to modify identity column IDUSER
PostPosted: Mon Jan 31, 2011 3:09 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Code:
<generator class="increment" />


This generator uses an internal counter in Hibernate to generate the id and doesn't work with database-generated id:s. I think you should use the identity generator instead. I haven't tried Derby but it works just fine with MySQL.

Code:
<generator class="identity" />


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.