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.currentSess ion();
Query query = session.getNamedQuery("Sal esForecast SalesRepSu mmarySp");
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" ,loggedInU serID);
list = query.list();
HibernateUtils.closeSessio n();
}
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.SalesForecastSal esRepSumma rySp" callable="true">
<return alias="SalesForecastSalesR epSummaryS p" class="com.cynosure.sf.dom ain.SalesF orecast">
<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 SalesForecastSalesRepSumma rySp(:para 1, :para2, :para3, :para4, :para5, :para6, :para7) }
</sql-query>
</hibernate-mapping>
ERRORS-->
javax.servlet.ServletExcep tion: Filter execution threw an exception
root cause
java.lang.ExceptionInIniti alizerErro r
com.cynosure.sf.utils.Hibe rnateUtils .<clinit>( HibernateU tils.java: 22)
com.cynosure.sf.service.im pl.Securit yServiceIm pl.authent icateUser( SecuritySe rviceImpl. java:28)
com.cynosure.sf.security.S ecurityFil terRealm.b ooleanAuth enticate(S ecurityFil terRealm.j ava:14)
org.securityfilter.realm.S impleSecur ityRealmBa se.authent icate(Simp leSecurity RealmBase. java:107)
org.securityfilter.authent icator.For mAuthentic ator.proce ssLogin(Fo rmAuthenti cator.java :178)
org.securityfilter.filter. SecurityFi lter.doFil ter(Securi tyFilter.j ava:138)
root cause
org.hibernate.HibernateExc eption: Errors in named queries: dbo.SalesForecastSalesRepS ummarySp
org.hibernate.impl.Session FactoryImp l.<init>(S essionFact oryImpl.ja va:407)
org.hibernate.cfg.Configur ation.buil dSessionFa ctory(Conf iguration. java:1341)
com.cynosure.sf.utils.Hibe rnateUtils .<clinit>( HibernateU tils.java: 18)
com.cynosure.sf.service.im pl.Securit yServiceIm pl.authent icateUser( SecuritySe rviceImpl. java:28)
com.cynosure.sf.security.S ecurityFil terRealm.b ooleanAuth enticate(S ecurityFil terRealm.j ava:14)
org.securityfilter.realm.S impleSecur ityRealmBa se.authent icate(Simp leSecurity RealmBase. java:107)
org.securityfilter.authent icator.For mAuthentic ator.proce ssLogin(Fo rmAuthenti cator.java :178)
org.securityfilter.filter. SecurityFi lter.doFil ter(Securi tyFilter.j ava: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.
I have a stored procedure that gives values from multiple tables.
Java Class to get the data -->
List list = null;
try
{
Session session = HibernateUtils.currentSess
Query query = session.getNamedQuery("Sal
query.setParameter("para1"
query.setParameter("para2"
query.setParameter("para3"
query.setParameter("para4"
query.setParameter("para5"
query.setParameter("para6"
query.setParameter("para7"
list = query.list();
HibernateUtils.closeSessio
}
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.SalesForecastSal
<return alias="SalesForecastSalesR
<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 SalesForecastSalesRepSumma
</sql-query>
</hibernate-mapping>
ERRORS-->
javax.servlet.ServletExcep
root cause
java.lang.ExceptionInIniti
com.cynosure.sf.utils.Hibe
com.cynosure.sf.service.im
com.cynosure.sf.security.S
org.securityfilter.realm.S
org.securityfilter.authent
org.securityfilter.filter.
root cause
org.hibernate.HibernateExc
org.hibernate.impl.Session
org.hibernate.cfg.Configur
com.cynosure.sf.utils.Hibe
com.cynosure.sf.service.im
com.cynosure.sf.security.S
org.securityfilter.realm.S
org.securityfilter.authent
org.securityfilter.filter.
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.
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("Sal esForecast SalesRepSu mmarySp");
change it to
Query query = session.getNamedQuery("dbo .SalesFore castSalesR epSummaryS p");
2) check with '?' in the query instead of the named parameters
thanks
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("Sal
change it to
Query query = session.getNamedQuery("dbo
2) check with '?' in the query instead of the named parameters
thanks
Also you can try this method to call the stored procedure
http://blog.randompage.org/2008/03/stored-procedures-made-easy-with.html
http://blog.randompage.org/2008/03/stored-procedures-made-easy-with.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.