-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Stored procedure error using SQL server 2000
PostPosted: Wed Oct 28, 2009 3:50 am 
Newbie

Joined: Wed Oct 28, 2009 3:32 am
Posts: 2
Hi
I am trying to execute stored procedure in SQL server 2000 but i get "Error reading resource: contact.hbm.xml". I followed Hibernate tutorial but it is still getting error.

below is my code
contact.hbm.xml
Code:
<class name="springapp.web.Event" table="EVENTS">
           <id name="id" column="EVENT_ID">
               <generator class="identity" />
           </id>
           <property name="title" type="string" column="TITLE"  not-null="true"/>
           <property name="date" type="date" column="EVENT_DATE" not-null="true"/>
           <loader query-ref="getEventSP"></loader>
     </class>
   <sql-query name="getEventSP" callable="true">
      <return alias="getEventSP" class="springapp.web.Event">
         <return-property name="id" column="EVENT_ID"></return-property>
         <return-property name="title" column="TITLE"></return-property>
         <return-property name="date" column="EVENT_DATE"></return-property>
      </return>
      { ? = call selectAllEmployments(?) }
   </sql-query>


Event.java POJO
Code:
public class Event implements Serializable{
   
   private java.lang.Integer id;
   private java.lang.String  title;
   private Date date;
   
   public Date getDate() {
      return date;
   }
   public void setDate(Date date) {
      this.date = date;
   }
   public java.lang.Integer getId() {
      return id;
   }
   public void setId(java.lang.Integer id) {
      this.id = id;
   }
   public java.lang.String getTitle() {
      return title;
   }
   public void setTitle(java.lang.String title) {
      this.title = title;
   }
}


My main class
Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
tx = session.beginTransaction();
Query query = session.getNamedQuery("getEventSP");
query.setInteger(0,1);
List<Event> books = query.list();
  for (Iterator<Event> iter = books.iterator(); iter.hasNext();) {
   Event book =  iter.next();
   System.out.println("last name===>"+book.getTitle());;
}
tx.commit();

My procedure
Quote:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

ALTER Proc selectAllEmployments
--RETURn SYS_REFCURSOR
AS
--st_cursor SYS_REFCURSOR;
BEGIN
--OPEN st_cursor FOR
SELECT EMPLOYEE, EMPLOYER,
STARTDATE, ENDDATE,
REGIONCODE, EID, VALUE, CURRENCY
FROM EMPLOYMENT;
--RETURN st_cursor;
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

The above code gives me "Error reading resource: contact.hbm.xml" .Do hibernate require refcursor ?.


Top
 Profile  
 
 Post subject: Re: Stored procedure error using SQL server 2000
PostPosted: Tue Nov 03, 2009 12:41 am 
Newbie

Joined: Wed Oct 28, 2009 3:32 am
Posts: 2
I found the issue.My Hibernate.jar was old i changed to Hibernate-3.0.5.jar.Also i made some changes in hbm.xml file to this
{ call selectAllEmployments(:first) }

Now i can able to get the results properly.I have given below the working code for SQLServer stored procedure
events.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="DAO.procDAO.Events">
        <id name="event_id" />
        <property name="title" />
        <property name="event_date" />
    </class>
   <sql-query name="getEventSP" callable="true">
      <return alias="events" class="DAO.procDAO.Events">
         <return-property name="event_id" column="event_id" ></return-property>
         <return-property name="title" column="title"></return-property>
         <return-property name="event_date" column="event_date"></return-property>
      </return>
      { call getEvent(:first) }
   </sql-query>
</hibernate-mapping>

POJO : Events.java
Code:
package DAO.procDAO;

import java.io.Serializable;

public class Events implements Serializable {
    private Long event_id;
    private java.lang.String title;
    private java.util.Date event_date;

    public Events() {

    }

   public java.util.Date getEvent_date() {
      return event_date;
   }

   public void setEvent_date(java.util.Date event_date) {
      this.event_date = event_date;
   }

   public Long getEvent_id() {
      return event_id;
   }

   public void setEvent_id(Long event_id) {
      this.event_id = event_id;
   }

   public java.lang.String getTitle() {
      return title;
   }

   public void setTitle(java.lang.String title) {
      this.title = title;
   }

   
}


From Java File
Code:

protected List getStoredProcedure(java.lang.String namedQuery,HashMap mapValue){
       startOperation();
       Query query = session.getNamedQuery(namedQuery);
       Set keySet = mapValue.keySet();
       Iterator keySetIterator = keySet.iterator();
       while(keySetIterator.hasNext()){
          Object key = keySetIterator.next();
          Object value = mapValue.get(key);
          System.out.println("key="+key+",value="+value);
          query.setParameter(key.toString(),value.toString());
       }
        tx.commit();
       return query.list();
    }
.The above code is a working code


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.