Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Attempt to modify an identity column

 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I generated classes from database via Hibernate.

Database ddl:



Aaa.hbm.xml:



Bussiness logic:
Reading a Aaa from database is ok.
But save a Aaa into database

throw following exception:



Could you help me please.
[ August 24, 2008: Message edited by: manu chaox ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe, you instruct hibernate to generate the id for you, then why are you trying to pass the value for it.

That might be the reason. I assume, you are worried about knowing the value hibernate is gonna generate for you. If thats the case, your save method would return the generated key for you to use further.

Cheers.
 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These exceptions throw with commented setId:

[ August 25, 2008: Message edited by: manu chaox ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try


instead of,

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by manu chaox:
These exceptions throw with commented setId:


There is no exception shown in your post.
 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is the same problem(same exception.)




quote : o riginally posted by manu chaox:
These exceptions throw with commented setId:



There is no exception shown in your post.

Sorry, I thought previous exception(see above).
[ August 25, 2008: Message edited by: manu chaox ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using session.save()?
 
Ramesh Srinivasan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by manu chaox:

is the same problem(same exception.)




Sorry, I thought previous exception(see above).

[ August 25, 2008: Message edited by: manu chaox ]


I believe bad SQL passed for your RDBMS. Check your datasource in your hibernate and configuration. Also check if you are using any db scripts.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try this, to print the actual SQL on the console.

 
Raghu Dg
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<id name="id" column="ID">
<generator class="identity"/>
</id>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic