Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7958599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:26:49+00:00 2026-06-04T04:26:49+00:00

I have been able to execute a Stored Procedure in hibernate to map the

  • 0

I have been able to execute a Stored Procedure in hibernate to map the result query into a Java Bean.

For example, I have this file called Profesor.hbm.xml:

<hibernate-mapping>
        <class name="model.Profesor" table="Profesor" catalog="dbo">
            <id name="idProfesor" type="int">
                <column name="idProfesor" />
                <generator class="assigned" />
            </id>
        <property name="Nombre" type="string">
            <column name="Nombre"  length="25" not-null="false" />
        </property>
        <property name="ApellidoP" type="string">
            <column name="ApellidoP" length="20" not-null="false" />
        </property>

        <property name="ApellidoM" type="string">
            <column name="ApellidoM" length="20" not-null="false" />
        </property>
            </class>

        <sql-query name="getProfesors" callable="true">
        <return alias="getProfesors" class="model.Profesor">

        <return-property name="idProfesor" column="idProfesor"/>
        <return-property name="Nombre" column="Nombre"/>
        <return-property name="ApellidoP" column="ApellidoP"/>
        <return-property name="ApellidoM" column="ApellidoM"/>
        </return>
        exec getProfesors :idTT
        </sql-query>
</hibernate-mapping>

And then in my Profesor class I have the following code:

SessionFactory sf = new Configuration().configure().buildSessionFactory();
session = sf.getCurrentSession();

public List <Profesor> getProfesors(String idTT){
    session.beginTransaction();

    query.setString("idTT", idTT);

return query.list();
}

This works perfectly, I have no problem, the stored procedure executes and it populates my model Class named Profesor with the results.

Now I have another stored procedure which INSERTs data to create a new Profesor in the Database.

I tried something like this with no success:

session.beginTransaction();
Connection c = session.connection();
CallableStatement cs = c.prepareCall( "{call addProfesor(?,?,?)}" ) ;
cs.setString(1, "George");
cs.setString(2, "Williams");
cs.setString(3, "Mathematics");

cs.executeUpdate();

It doesn’t even show me an error message, the data just won’t insert.
I was also reading that just like there is a <“sql-query”> tag, there is a <“sql-insert”>
but then I can’t see the way to call that <“sql-insert”> because it doesn’t have a “name” attribute just like sql-query does.

With <“sql-query”> we could do:

 Query query =session.getNamedQuery("getProfesors");

Just like I showed before, but since sql-insert doesnt have that attribute name I don’t know how to do it. I’m also forced to use Stored procedures since it’s a very special requirement, otherwise I would have used other Hibernate persistance features.

Any help would be really appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:26:50+00:00Added an answer on June 4, 2026 at 4:26 am

    Another way to do it is call the stored proc from a prepared statement. This is potentially useful if the stored procedure updates more than one record (batch updates).

    PreparedStatement ps = getSession().connection().prepareStatement("{exec sp_batchRateUpdate}");
    ps.execute();
    

    Please note though: hibernate sessions’ connection() method has been deprecated since Hibernate 3.2.4 (https://hibernate.onjira.com/browse/HHH-2603)
    An alternative to this deprecation temporarily, we can use:

    PreparedStatement ps = ((SessionFactoryImplementor)sessionFactory).getConnectionProvider()
                        .getConnection().prepareStatement("{exec sp_batchRateUpdate}");
    ps.execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this excel file which I have been able to write the data
I've been reading similar questions to this issue and have been able to get
Although I have been able to see the last ran query which is a
I have literally been searching for this for weeks. I am a novice java
I have been able to retrieve values into my form.The values are inserted into
I have been able to design my layout so that it has 2 columns
I have been able to set up OBDC in Filemaker, and added table ,
Hi I have been able to extract a VARCHAR to a date using string_to_date
What I have been able to grasp from reading the source and documentation from
So far the only way I have been able to keep index.yaml updated when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.