This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Custom SQL - avoid Id being used

 
sir proof
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I've got a lot of answers to my questions here, even if I never asked them. But now I'm fronting a serious problem:

We want to execute DML to the database with stored procedures. Hibernate offers the possibility to define with @SQLInsert, -update, -delete your own prepared statements, which uses hibernate to "generate" the insert, update etc. statements. e.g. I have the following class definition:




The problem is, that the id is generated by the procedure itself and should not be passed or generated by hibernate. But if the id is not used in the prepared statement I get a:



Because Hibernate tries to put the value of the id into the statement and does not find a place holder like ':id'.

The definition





does only have impact on non-key-properties, so that they where skipped.

Does anybody know this behavior and can help me out of this mess?

Thanks and bye
Peter
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't deal with Stored Procedures much but I think you need to look at your @GeneratedValue. Take a look at this and see if it gets you on the right path

http://stackoverflow.com/questions/7877759/hibernate-receive-generated-id-from-a-callable-custom-insert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic