• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

SqlException: Attempt to modify an identity column 'USER_ID'

 
Ranch Hand
Posts: 35
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
Any advise?
 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried to save the object using session.save() method?
 
Royston Monteiro
Ranch Hand
Posts: 35
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any more help?
 
reply
    Bookmark Topic Watch Topic
  • New Topic