File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Custom SQL - avoid Id being used Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Custom SQL - avoid Id being used" Watch "Hibernate Custom SQL - avoid Id being used" New topic
Author

Hibernate Custom SQL - avoid Id being used

sir proof
Greenhorn

Joined: Aug 17, 2012
Posts: 1
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

Joined: Mar 07, 2010
Posts: 1676
    
    7

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


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Custom SQL - avoid Id being used