Link to home
Start Free TrialLog in
Avatar of SaiLoveAll
SaiLoveAll

asked on

Hibernate Exception - Errors in named queries

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.
Avatar of SaiLoveAll
SaiLoveAll

ASKER

Please take a look at the below link

https://www.experts-exchange.com/questions/24835677/Hibernate-Mapping-Stored-Proc-result-from-multiple-tables.html

which was my early post. But, didnt get thought the issue since then. Needed Help really bad.
Avatar of Gurvinder Pal Singh
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
ASKER CERTIFIED SOLUTION
Avatar of SaiLoveAll
SaiLoveAll

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial