I'm trying to use Hibernate to insert a row using a stored proc in a legacy database. I've been reading various bits on the web about using Hibernate with stored procs (including posts on Java Ranch), but I'm still confused. I'm totally new to Hibernate, so the issue could simply be a lack of understanding.
I populate a domain object and then map the domain object to the db table by way of the stored proc, or at least that's what I'm trying to do. The domain object (named "EventLog") is a POJO, the database is Sybase, and current app uses Spring/Hibernate. Here's how the mapping currently looks:
I'm trying to call this using the following code in my DAO:
I would include the source for the store proc, but it's very long (multiply pages).
Can anyone tell me if the mapping above has some obvious bug in it? One thing I'm unclear on is what the "table" attribute should be in this case, i.e. the stored proc name, the actual db table name? I did try the table name and got an exception saying the columns in the mapping didn't match the columns in the table (which they don't, since I used the stored proc's properties as the "column" names in the mapping).
Any help would be appreciated. And if I need to post some more code, please let me know what would be helpful.
Yeah, if the properties in your mapping do not match a table that will not work. Try removing the table attribute completely, and remove all the column attributes on the properties also.
The number of parameters "?" in your <sql-insert> do not match the number of id and properties in your mapping. You have 7 "?" in the <sql-insert> and 8 properties and ids in your mapping. Order is important too.