Announcement Announcement Module
Collapse
No announcement yet.
Spring With Hibernate Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring With Hibernate Problem

    Hi,

    Iam new to the spring framework. Currently Iam working on spring with hibernate.

    Iam trying to get a list of values from the stored function emp_listtest.

    Below is my Emp.hbm.xml:

    <sql-query name="list_query" callable="true">
    <return alias="emp" class="EditempdetailsForm">
    <return-property name="id" column="k_id" />
    <return-property name="empname" column="emp_name" />
    <return-property name="empdesignation" column="emp_designation" />
    <return-property name="empsalary" column="emp_salary" />
    </return>
    { ? = call emp_listtest()}
    </sql-query>


    and my stored function is:

    CREATE OR REPLACE FUNCTION EMP_LISTTEST RETURN SYS_REFCURSOR
    AS
    DECLARE
    st_cursor SYS_REFCURSOR;
    BEGIN
    OPEN st_cursor FOR SELECT k_id,emp_name,emp_designation,emp_salary from krishnalist;
    RETURN st_cursor;
    END;


    Iam using getHibernateTemplate provided by springs. How can i access the resultset with named queries?

    Thanks,
    yvk

  • #2
    Code:
    List results = getHibernateTemplate().findByNamedQuery("list_query");

    Comment


    • #3
      I tried it before.

      But iam getting the below problem.

      org.springframework.orm.hibernate.HibernateQueryEx ception: Not all positional parameters have been set. Expected 1, set [] [

      { ? = call emp_listtest()}
      ]; nested exception is net.sf.hibernate.QueryException: Not all positional parameters have been set. Expected 1, set [] [

      { ? = call emp_listtest()}
      ]
      .


      I also observed without stored procedcure concept i.e with the below code your given code worked successfully.

      i.e In Emp.hbm.xml:

      <sql-query name="list_query">
      <return alias="person" class="EditempdetailsForm"/>
      SELECT {person}.k_id AS {person.id}, {person}.emp_name AS {person.empname},
      {person}.emp_designation AS {person.empdesignation},
      {person}.emp_salary AS {person.empsalary}
      FROM krishnalist {person}

      </sql-query>

      Thanks,
      yvk

      Comment


      • #4
        You don't need '?=' part in the sp definition.

        Comment


        • #5
          In the above procedure, assume I used IN,OUT parameters.

          How can I set IN,OUT paramters if I used named query and HibernateTemplate class?

          Thanks,
          yvk

          Comment


          • #6
            If you need out parameters it's not a query, as queries do not have out parameters. Use JdbTemplate or StoredProcedure.

            Comment

            Working...
            X