[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hibernate Exception - Errors in named queries

Posted on 2009-12-29
6
Medium Priority
?
1,932 Views
Last Modified: 2013-11-24
Using Struts 1.3 , Hibernate 3 and Tomcat 5.5v

I have a stored procedure that gives values from multiple tables.

Java Class to get the data -->
                                   List list = null;
                     try
                  {
                  Session session = HibernateUtils.currentSession();
                                      Query query = session.getNamedQuery("SalesForecastSalesRepSummarySp");
                  query.setParameter("para1", marketID );
                  query.setParameter("para2", statusID );
                  query.setParameter("para3",quarterID);
                  query.setParameter("para4", month );
                  query.setParameter("para5",year );
                  query.setParameter("para6",customer );
                  query.setParameter("para7",loggedInUserID);

                  list = query.list();
                                    
                  HibernateUtils.closeSession();
                                    
                  }
            catch (Exception e) {
                        System.out.println(e);
                        }
            return list;



POJO (SalesForecast.java)
______________________

public class SalesForecast implements java.io.Serializable{
            
            private Short managerId;  
            private Short saleaRepId;  
            private Short totalPrice;
            private BigDecimal forecast;    
            private BigDecimal pending;    
            private BigDecimal booked;
            private BigDecimal lost;
            
            public SalesForecast()
            {
                  super();
            }
            public SalesForecast(Short managerId
                        , Short saleaRepId
                        , Short totalPrice
                        , BigDecimal forecast
                        , BigDecimal pending
                        , BigDecimal booked
                        ,BigDecimal lost)
            {
                  super();
                  this.managerId = managerId;
                  this.saleaRepId = saleaRepId;
                  this.totalPrice = totalPrice;
                  this.forecast = forecast;
                  this.pending = pending;
                  this.booked = booked;
                  this.lost=lost;
            }
            
            public Short getManagerId() {
                  return managerId;
            }
            public void setManagerId(Short managerId) {
                  this.managerId = managerId;
            }
            
            
            public Short getSaleaRepId() {
                  return saleaRepId;
            }

            public void setSaleaRepId(Short saleaRepId) {
                  this.saleaRepId = saleaRepId;
            }

            

            public Short getTotalPrice() {
                  return totalPrice;
            }

            public void setTotalPrice(Short totalPrice) {
                  this.totalPrice = totalPrice;
            }

            public BigDecimal getForecast() {
                  return forecast;
            }
            public void setForecast(BigDecimal forecast) {
                  this.forecast = forecast;
            }
            public BigDecimal getPending() {
                  return pending;
            }
            public void setPending(BigDecimal pending) {
                  this.pending = pending;
            }
            public BigDecimal getBooked() {
                  return booked;
            }
            public void setBooked(BigDecimal booked) {
                  this.booked = booked;
            }

            public BigDecimal getLost() {
                  return lost;
            }

            public void setLost(BigDecimal lost) {
                  this.lost = lost;
            }
            
}



SalesForecast.hbm.xml
___________________
<hibernate-mapping>

<sql-query name="dbo.SalesForecastSalesRepSummarySp" callable="true">
<return alias="SalesForecastSalesRepSummarySp" class="com.cynosure.sf.domain.SalesForecast">
<return-property name="managerId" column="ManagerId"/>
<return-property name="saleaRepId" column="SaleaRepId"/>
<return-property name="totalPrice" column="TotalPrice"/>
<return-property name="forecast" column="Forecast"/>
<return-property name="pending" column="Pending"/>
<return-property name="booked" column="Booked"/>
<return-property name="lost" column="Lost"/>

</return>
 { ? = call SalesForecastSalesRepSummarySp(:para1, :para2, :para3, :para4, :para5, :para6, :para7) }

</sql-query>
</hibernate-mapping>

ERRORS-->

javax.servlet.ServletException: Filter execution threw an exception


root cause

java.lang.ExceptionInInitializerError
      com.cynosure.sf.utils.HibernateUtils.<clinit>(HibernateUtils.java:22)
      com.cynosure.sf.service.impl.SecurityServiceImpl.authenticateUser(SecurityServiceImpl.java:28)
      com.cynosure.sf.security.SecurityFilterRealm.booleanAuthenticate(SecurityFilterRealm.java:14)
      org.securityfilter.realm.SimpleSecurityRealmBase.authenticate(SimpleSecurityRealmBase.java:107)
      org.securityfilter.authenticator.FormAuthenticator.processLogin(FormAuthenticator.java:178)
      org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:138)


root cause

org.hibernate.HibernateException: Errors in named queries: dbo.SalesForecastSalesRepSummarySp
      org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:407)
      org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
      com.cynosure.sf.utils.HibernateUtils.<clinit>(HibernateUtils.java:18)
      com.cynosure.sf.service.impl.SecurityServiceImpl.authenticateUser(SecurityServiceImpl.java:28)
      com.cynosure.sf.security.SecurityFilterRealm.booleanAuthenticate(SecurityFilterRealm.java:14)
      org.securityfilter.realm.SimpleSecurityRealmBase.authenticate(SimpleSecurityRealmBase.java:107)
      org.securityfilter.authenticator.FormAuthenticator.processLogin(FormAuthenticator.java:178)
      org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:138)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.


I have been trying to resolve it for a while. But cannot find way out. Any help will be appreciated. Thanks in Advance.
0
Comment
Question by:SaiLoveAll
  • 2
  • 2
4 Comments
 

Author Comment

by:SaiLoveAll
ID: 26149185
Please take a look at the below link

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_24835677.html

which was my early post. But, didnt get thought the issue since then. Needed Help really bad.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26157071
Based on which database you are using, check the following
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html#sp_query
http://forum.springsource.org/showthread.php?t=19472
http://javaspots.blogspot.com/2008/12/using-stored-procedures-with-hibernate.html

please check the following
1) from
Query query = session.getNamedQuery("SalesForecastSalesRepSummarySp");
change it to
Query query = session.getNamedQuery("dbo.SalesForecastSalesRepSummarySp");

2) check with '?' in the query instead of the named parameters

thanks
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26157074
Also you can try this method to call the stored procedure
http://blog.randompage.org/2008/03/stored-procedures-made-easy-with.html
0
 

Accepted Solution

by:
SaiLoveAll earned 0 total points
ID: 26211494
Fixed it by setting up a class tag with reference to the POJO and matching the resultset to the elements in the domain class. Thanks for your response Friends.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month19 days, 6 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question