Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: sql-insert sql-updat sql-delete

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amardeep Salkar
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic