Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert via Hibernate and Stored Procs

 
Janna Davis
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks.
 
Saket Barve
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel your named query:



may need modifications to include the return type and its details. Did you take a look at Native SQL?

I opted to simply use CallableStatement in tandem with Hibernate's Session and Connection objects in order to invoke the only stored procedure in the application I am presently working in.

Let us know which path you take.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Try those

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic