• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

hibernate stored procedures insert scenario

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have an .xhtml page that collect Widget information from a given user. After the user enters the infomation, I have a stored procedure that will take the information and insert it into a Widget table using session.save. Now for the tricky part, when the user initially entered the information there was no database record associated with this Widget thus no primary key. After the proc performs the insert, I need to somehow associate the primary key with the current Widget object. Does hibernate provide a mechanism for this?
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your session.save() returns the id of the inserted record.
Use that id and associate with the widget.
 
Anthony Sykes
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will work even when using stored procedures?
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a nice article on stored procedures with Hibernate. This might answer some questions:

Stored Procedures with Hibernate

The worst case scenario is that you simply get back the id of the inserted or queried record. Once you have that id, as was said before, just load that object using either a DAO or the Hibernate Session itself. Then use that loaded POJO and volley it back and forth between your data layer and your web layer.

-Cameron McKenzie

 
Anthony Sykes
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will you still have access to the same internal hibernate features you do without using stored procedures?
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it all depends on what your resultset returns to you.

I'm not overly experienced in this aspect, but I don't think your resultset is going to return to you any persistent objects. So, I would imagine that any persistent POJO you want would need to be loaded from the Hibernate Session, using the primary key that is contained in the resultSet being returned.

Feel free to correct me on this point, but it makes sense to me.

-Cameron
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic