Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Insert via Hibernate and Stored Procs

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.

Ranch Hand
Posts: 237
  • 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.
Posts: 17346
Mac IntelliJ IDE 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

Attractive, successful people love this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic