Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SqlException: Attempt to modify an identity column 'USER_ID'

 
Royston Monteiro
Ranch Hand
Posts: 35
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
The following is my hibernate mapping file:

The following is my Data Class:

When I say:


I get the exception :


Any idea why? I am using derby database.
The hibernate documentation says this about identity of the generator:


Any help would be much appreciated.

Thanks in advance
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you're trying to update the identifier column on an entity. You can't do that.

Please try your best to use descriptive subject lines. Almost every other post these days is about Hibernate.

Thanks.

-Cameron McKenzie
 
Royston Monteiro
Ranch Hand
Posts: 35
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cameron.
My question is this:
Shouldn't we declare and map all the fields in the backing object(identity and non-identity fields)?
I have declared all the fields in the object that is mapped to the table:


When I try to add a new row to the database, I create a new instance of this class by setting the USER_NAME and USER_MAIL fields to Strings. The field mapped to the identity column gets its default values of 0. Finally, I attempt to add this new row by calling hibernateTemplate.save(object).

Is this the right way to do it?

Please help.



 
Royston Monteiro
Ranch Hand
Posts: 35
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
Any advise?
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried to save the object using session.save() method?
 
Royston Monteiro
Ranch Hand
Posts: 35
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harpreet Singh janda wrote:Have you tried to save the object using session.save() method?

I havent tried session.save

I am using spring with hibernate.

These are the logged errors:
 
Royston Monteiro
Ranch Hand
Posts: 35
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any more help?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic