aspose file tools*
The moose likes Object Relational Mapping and the fly likes SqlException: Attempt to modify an identity column 'USER_ID'  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "SqlException: Attempt to modify an identity column Watch "SqlException: Attempt to modify an identity column New topic
Author

SqlException: Attempt to modify an identity column 'USER_ID'

Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

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

Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Apr 25, 2008
Posts: 35

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

Joined: Apr 25, 2008
Posts: 35

Hi Folks,
Any advise?
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Have you tried to save the object using session.save() method?
Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

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

Joined: Apr 25, 2008
Posts: 35

Any more help?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SqlException: Attempt to modify an identity column 'USER_ID'