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