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 1077779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:37:35+00:00 2026-05-16T21:37:35+00:00

I just started learning hibernate last night and its rather fun. I am some

  • 0

I just started learning hibernate last night and its rather fun. I am some trouble calling a stored procedure as a sql-query with hibernate. I have attached the source and the error, please help me. Thanks 🙂

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Example" table="example">
   <id name="user_id" column="id" >
   <generator class="increment"/>
  </id>
  <property name="user_data">
    <column name="data"/>
  </property>
 </class>

<!-- sql-query must be after class --> 

<sql-query name="getRecordsSP" callable="true" >
<return class="Example">
<return-property name="user_id" column="user_id"></return-property>
<return-property name="user_data" column="user_data"></return-property>
</return>
{call getRecords}
</sql-query>

</hibernate-mapping>

This is the java file :::

    import java.util.Iterator;
    import java.util.List;

    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;


    public class SelectProc {


        public static void main(String[] args) {

            Session session = null;
            //String query = "select example.id, example.data from Example example";

            try{

                SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
                session = sessionFactory.openSession();

                System.out.println("selecting records");
                Query q = session.getNamedQuery("getRecordsSP");
        //      Query q =  session.createSQLQuery("call getRecords","",Example.class);

                System.out.print("Done");
                List l = q.list();


                for(Iterator it = l.iterator() ;it.hasNext();){
                    Object row [] = (Object [])it.next();
                    System.out.println(row.length);
            //      System.out.println(row[0]);
            //      System.out.println("ID " + row[0]);
            //  System.out.println("Data "+ row[1]);
                }

            }
            catch (Exception e) {
                e.printStackTrace();
            }
            finally{
                session.flush();
                session.close();

        }
    }
}

The error is:::

call getRecords}

18:33:41,346  WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: S0022
18:33:41,347 ERROR JDBCExceptionReporter:46 - Column 'id0_' not found.
18:33:41,348  WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: S0022
18:33:41,349 ERROR JDBCExceptionReporter:46 - Column 'id0_' not found.
18:33:41,349 ERROR JDBCExceptionReporter:38 - Could not execute native SQL query
java.sql.SQLException: Column 'id0_' not found.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)
    at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2813)
    at org.hibernate.type.IntegerType.get(IntegerType.java:18)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
    at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:541)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:233)
    at org.hibernate.loader.Loader.doQuery(Loader.java:337)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:167)
    at org.hibernate.loader.Loader.doList(Loader.java:1201)
    at org.hibernate.loader.Loader.list(Loader.java:1186)
    at org.hibernate.loader.SQLLoader.list(SQLLoader.java:121)
    at org.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:2212)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:85)
    at SelectProc.main(SelectProc.java:28)
org.hibernate.JDBCException: Could not execute native SQL query
    at org.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:2215)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:85)
    at SelectProc.main(SelectProc.java:28)
Caused by: java.sql.SQLException: Column 'id0_' not found.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1144)
    at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2813)
    at org.hibernate.type.IntegerType.get(IntegerType.java:18)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
    at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
    at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:541)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:233)
    at org.hibernate.loader.Loader.doQuery(Loader.java:337)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:167)
    at org.hibernate.loader.Loader.doList(Loader.java:1201)
    at org.hibernate.loader.Loader.list(Loader.java:1186)
    at org.hibernate.loader.SQLLoader.list(SQLLoader.java:121)
    at org.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:2212)
    ... 2 more
  • 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-05-16T21:37:36+00:00Added an answer on May 16, 2026 at 9:37 pm
    import java.sql.CallableStatement;
    import java.sql.ResultSet;
    import java.util.Iterator;
    import java.util.List;
    
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    
    
    
    public class SelectPP {
    
    
        public static void main(String[] args) {
    
            Session session = null;
            //String query = "select example.id, example.data from Example example";
            CallableStatement callableStatement = null;
            ResultSet resultSet = null;
    
            try{
    
                SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
                session = sessionFactory.openSession();
    
                System.out.println("selecting records");
        //      Query q = session.getNamedQuery("getRecordsSP");
        //      Query q =  session.createSQLQuery("call getRecords","",Example.class);
        //      Query q = session.getNamedQuery("getRecordsSP");
    
                callableStatement = session.connection().prepareCall("{call getRecords}");
                callableStatement.execute();
    
                resultSet = callableStatement.getResultSet();
    
                while(resultSet.next()){
                    System.out.println(resultSet.getInt(1));
                    System.out.println(resultSet.getString(2));
                }
    
                //resultSet.
    
                System.out.print("Done");
                //List l = q.list();
    
    
            //  for(Iterator it = l.iterator() ;it.hasNext();){
            //      Object row [] = (Object []) it.next();
    
            //      Example row = (Example) it.next();
            //      System.out.println(row.getUser_id());
            //      System.out.println(row.getUser_data());
            //      System.out.println(row.length);
            //      System.out.println("ID " + row[0]);
            //  System.out.println("Data "+ row[1]);
    
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            finally{
                session.flush();
                session.close();
            }
        }
    }
    

    I basically redesign the input without using hibernate getNamedQuery, but the java.sql class and it worked!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning LINQ to SQL, and so far I'm impressed with the
I just started learning Java and I'm having trouble formatting string. In the problem
Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter. I need some
I just started learning JS the other day and am (of course) having some
I just started learning HTML5, I started with normal text file and changed its
I just started learning SQL a couple of days ago, and I'm trying to
I just started learning how to use SwiftMailer and I am having trouble sending
I just started learning some ruby, and I want to do something like this:
I just started learning Java and I encountered some problems with the tag in
Just started learning NHiberate. It seems rather tedious to write proper hbm.xml config files

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.