-->
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.  [ 1 post ] 
Author Message
 Post subject: calling stored procedure from hibernate, problem
PostPosted: Thu Jan 29, 2009 2:41 am 
Newbie

Joined: Mon Oct 06, 2008 4:31 am
Posts: 1
Hi, I am having problem in executing stored procedure using hibernate.

Based on the google search, I have tried 2 types of annotations

Code:
@NamedQuery(
      name = "test",
      query = "call test()",   
      fetchSiz=10,
      //callable = true,
      readOnly = false
      )


Code:
@javax.persistence.NamedQuery(
            name = "test",
      query = "call test()"   
      
      callable = true,
      readOnly = false
      )



And here is my method to execute the stored procedure.I am using HibernateTemplate approach (using spring)

Code:
/**
    * Support for executing a stored procedure
    * @param queryString procedure name
    * @return
    */
   public int executeStoredProcedure(final String  queryString) throws DAOException {
      Integer count = null;
      try{
      
         //Query result = createQuery(query);
         //result.setString(0, id);
         count = (Integer)getHibernateTemplate().executeWithNativeSession(new HibernateCallback() {
               public Object doInHibernate(Session session) throws HibernateException, SQLException {
                     
                      return (new Integer(session.getNamedQuery(queryString).executeUpdate()));
               }
           });

         
               
      }catch(Exception ex){
         ex.printStackTrace();
         throw new DAOException("unable to execute stored procedure query:" + queryString,ex);
         
      }
      return count.intValue();
   }   



But I am getting following exception

Code:
org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: test; nested exception is org.hibernate.MappingException: Named query not known: test
   at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:661)
   at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at com.springboard.progressives.dao.JackpotDAO.executeStoredProcedure(JackpotDAO.java:111)
   at com.springboard.progressives.MainBean.test(MainBean.java:37)
   at com.springboard.progressives.Main.main(Main.java:23)


Please suggest a proper solution.

Thanks
harinath


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

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.