wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate: sql-insert  sql-updat sql-delete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: sql-insert  sql-updat sql-delete" Watch "Hibernate: sql-insert  sql-updat sql-delete" New topic
Author

Hibernate: sql-insert sql-updat sql-delete

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Hi:

I want to used sql-delete in my classes, but I don't know how to set the input parameter. From Hibernate documentation

<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>
</class>

How can I set the input parameters?
Thanks


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Amardeep Salkar
Ranch Hand

Joined: May 22, 2008
Posts: 46
Use This code in your Action Class or DAO Class.
SessionImplementor is an Interface which are used to for collable statement
you should import SessionImplementor....
/*
import org.hibernate.engine.SessionImplementor;

SessionFactory sf = new Configuration().configure().buildSessionFactory();
session =sf.openSession();
SessionImplementor sesImp=(SessionImplementor) session;
CallableStatement cs=null;
PreparedStatement ps = null;
// for delete..
// for Insert ..
// Call any StoreProcedure OR Functions...
cs = sesImp.getBatcher().prepareCallableStatement("
{call StoreProcedureFunction()}");
cs.executeUpdate();
tx.commit();
*/

Its work fine....
[ August 08, 2008: Message edited by: Amardeep Salkar ]
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Salkar:

Thank you for your reply, however it didn't answer my question.

I am trying to use <sql-delete />, <sql-insert/>, and <sql-update/>
tags. Just like in the Hibernate reference manual section 16.3.

<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>
</class>

I couldn't find any example on how to set the in/out parameters.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by Hanna Habashy:
Salkar:

Thank you for your reply, however it didn't answer my question.

I am trying to use <sql-delete />, <sql-insert/>, and <sql-update/>
tags. Just like in the Hibernate reference manual section 16.3.

<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>
</class>

I couldn't find any example on how to set the in/out parameters.


In this particular place you don't set the in/out parameters. Hibernate under the covers does this. Usually when Hibernate creates a SessionFactory and reads the config files it creates insert/update/delete statements for all your <class> mappings and uses them. This setting you are using overwrites the default queries, but even in those cases Hibernate is the one that fills it up with data for you.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
In this particular place you don't set the in/out parameters. Hibernate under the covers does this. Usually when Hibernate creates a SessionFactory and reads the config files it creates insert/update/delete statements for all your <class> mappings and uses them. This setting you are using overwrites the default queries, but even in those cases Hibernate is the one that fills it up with data for you.

Mark


But how does hibernate knows about my IN parameters?
For example: I have delete stored proc. that takes the ID of the user who is attempting to deleted the record as an input parameter. We need this data for auditing purpose.
i.e.
{ call delete_record(:recordId, :userId)
Samrat Gadamsetty
Greenhorn

Joined: Feb 10, 2011
Posts: 29
Expecting someone will update the thread...

How <sql-update> will map with the parameters...

From my Example :



Please Correct my <sql-update> statement

update_SamratTest_1 will take two parameters empid and empsal..

Thanks in advance..
Samrat
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: sql-insert sql-updat sql-delete
 
Similar Threads
Problem with hibernate
JOIN syntax for HQL . Need help!
procedure calling in hibernate
Hibernate Newbie - 1 to Many Relation Tutorial
one-to-many relation