-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem querying with a stored procedure
PostPosted: Thu Jun 02, 2005 2:20 pm 
Newbie

Joined: Wed Jun 01, 2005 4:37 pm
Posts: 3
Hi,

With eclipse 3.0.2, hibernate 3.0, sql server 2000, I am having problems using stored procedure for querying via a named query. Basically it complains about invalid mapping, Attribute "callable" is not declared for element "sql-query".

here is the stored procedure

create procedure spGetEconActual
@revisionID int,
@quarterID int
as
begin
select quarterID, revisionID into #temp
from CCEconActual
where revisionID<= @revisionID and quarterID<=@quarterID

select a.*
from CCEconActual a,
( select quarterID, max(revisionID) revisionID
from #temp
group by quarterID) b
where a.quarterID=b.quarterID and a.revisionID=b.revisionID
order by a.quarterID

end

Thanks a billion
Hibernate version:3.0

Mapping documents:</class>

<sql-query name="spGetEconActual" callable = "true">
<return alias="cea" class="CceconActual">
<return-property name="CCEconActualID" column="CCEconActualID"/>
<return-property name="quarterId" column="quarterId"/>
<return-property name="nco" column="nco"/>
<return-property name="bkp" column="bkp"/>
<return-property name="tb10y" column="tb10y"/>
<return-property name="tb3m" column="tb3m"/>
<return-property name="gdp" column="gdp"/>
<return-property name="unEmp" column="unEmp"/>
<return-property name="sp500" column="sp500"/>
<return-property name="baaAaaSpread" column="baaAaaSpread"/>
<return-property name="usspec" column="usspec"/>
<return-property name="cprate" column="cprate"/>
<return-property name="userId" column="userId"/>
<return-property name="lastUpdated" column="lastUpdated"/>
</return>
{ ?=call spGetEconActual(?,?) }
</sql-query>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
List CceconActuals = session.getNamedQuery("spGetEconActual")
.setInteger(0, iRevision)
.setInteger(1, quarterID)
.list();


Full stack trace of any exception that occurs:
[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43[ERROR] 44:43Exception from static block: Error reading resource: CceconActual.hbm.xml
org.hibernate.MappingException: Error reading resource: CceconActual.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at com.bac.pao.lossforecast.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:30)
at com.bac.pao.lossforecast.dao.SqlserverCCDAO.getRevision(SqlserverCCDAO.java:31)
at com.bac.pao.lossforecast.dao.DataAccessFacade.getRevision(DataAccessFacade.java:135)
at com.bac.pao.lossforecast.dao.DataAccessFacade.main(DataAccessFacade.java:405)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:394)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 10 more
Caused by: org.xml.sax.SAXParseException: Attribute "callable" is not declared for element "sql-query".
at org.apache.crimson.parser.Parser2.error(Parser2.java:3354)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1595)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:393)
... 11 more
java.lang.ExceptionInInitializerError
at com.bac.pao.lossforecast.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:35)
at com.bac.pao.lossforecast.dao.SqlserverCCDAO.getRevision(SqlserverCCDAO.java:31)
at com.bac.pao.lossforecast.dao.DataAccessFacade.getRevision(DataAccessFacade.java:135)
at com.bac.pao.lossforecast.dao.DataAccessFacade.main(DataAccessFacade.java:405)
Caused by: org.hibernate.MappingException: Error reading resource: CceconActual.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at com.bac.pao.lossforecast.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:30)
... 3 more
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:394)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 10 more
Caused by: org.xml.sax.SAXParseException: Attribute "callable" is not declared for element "sql-query".
at org.apache.crimson.parser.Parser2.error(Parser2.java:3354)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1595)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:393)
... 11 more
Exception in thread "main"


Name and version of the database you are using: SQL Server 2000


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 3:50 pm 
Newbie

Joined: Wed Jun 01, 2005 4:37 pm
Posts: 3
I'd like to add some additional info. The table has a foreign key. I generated the mapping doc with middlegen, then generated the pojos through hbm2java. I had to mass modify some fields within the generated files such as changing 2.0 to 3.0 and assigned to identity. The named query by stored procedure was mannually inserted by me.

Mapping doc (I removed some columns to make things clearer.):

<?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>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->


<class
name="com.bac.pao.lossforecast.dao.hibernate.CceconActual"
table="CCEconActual"
>

<meta attribute="class-description" inherit="false">
@hibernate.class
table="CCEconActual"
</meta>

<id unsaved-value="0"
name="cceconActualId"
type="java.lang.Integer"
column="CCEconActualID"
>
<meta attribute="field-description">
@hibernate.id
generator-class="identity"
type="java.lang.Integer"
column="CCEconActualID"

</meta>
<generator class="identity" />
</id>

<property
name="quarterId"
type="int"
column="quarterID"
not-null="true"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="quarterID"
length="10"
not-null="true"
</meta>
</property>
<property
name="nco"
type="java.math.BigDecimal"
column="NCO"
length="38"
>
<meta attribute="field-description">
@hibernate.property
column="NCO"
length="38"
</meta>
</property>

<!-- Associations -->

<!-- bi-directional many-to-one association to CceconActualRevision -->
<many-to-one
name="cceconActualRevision"
class="com.bac.pao.lossforecast.dao.hibernate.CceconActualRevision"
not-null="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="revisionID"
</meta>
<column name="revisionID" />
</many-to-one>
</class>

<sql-query name="spGetEconActual" callable = "true">
<return alias="cea" class="com.bac.pao.lossforecast.dao.hibernate.CceconActual">
<return-property name="cceconActualId" column="CCEconActualID"/>
<return-property name="quarterId" column="quarterId"/>
<return-property name="nco" column="nco"/>
</return>
{ ?=call spGetEconActual(?,?) }
</sql-query>
</hibernate-mapping>

--POJO
package com.bac.pao.lossforecast.dao.hibernate;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
* @hibernate.class
* table="CCEconActual"
*
*/
public class CceconActual implements Serializable {

/** identifier field */
private Integer cceconActualId;

/** persistent field */
private int quarterId;

/** nullable persistent field */
private BigDecimal nco;

/** persistent field */
private com.bac.pao.lossforecast.dao.hibernate.CceconActualRevision cceconActualRevision;

/** full constructor */
public CceconActual(Integer cceconActualId, int quarterId, BigDecimal nco, com.bac.pao.lossforecast.dao.hibernate.CceconActualRevision cceconActualRevision) {
this.cceconActualId = cceconActualId;
this.quarterId = quarterId;
this.nco = nco;
this.cceconActualRevision = cceconActualRevision;
}

/** default constructor */
public CceconActual() {
}

/** minimal constructor */
public CceconActual(Integer cceconActualId, int quarterId, com.bac.pao.lossforecast.dao.hibernate.CceconActualRevision cceconActualRevision) {
this.cceconActualId = cceconActualId;
this.quarterId = quarterId;
this.cceconActualRevision = cceconActualRevision;
}

/**
* @hibernate.id
* generator-class="identity"
* type="java.lang.Integer"
* column="CCEconActualID"
*
*/
public Integer getCceconActualId() {
return this.cceconActualId;
}

public void setCceconActualId(Integer cceconActualId) {
this.cceconActualId = cceconActualId;
}

/**
* @hibernate.property
* column="quarterID"
* length="10"
* not-null="true"
*
*/
public int getQuarterId() {
return this.quarterId;
}

public void setQuarterId(int quarterId) {
this.quarterId = quarterId;
}

/**
* @hibernate.property
* column="NCO"
* length="38"
*
*/
public BigDecimal getNco() {
return this.nco;
}

public void setNco(BigDecimal nco) {
this.nco = nco;
}


/**
* @hibernate.many-to-one
* not-null="true"
* @hibernate.column name="revisionID"
*
*/
public com.bac.pao.lossforecast.dao.hibernate.CceconActualRevision getCceconActualRevision() {
return this.cceconActualRevision;
}

public void setCceconActualRevision(com.bac.pao.lossforecast.dao.hibernate.CceconActualRevision cceconActualRevision) {
this.cceconActualRevision = cceconActualRevision;
}

public String toString() {
return new ToStringBuilder(this)
.append("cceconActualId", getCceconActualId())
.toString();
}

public boolean equals(Object other) {
if ( !(other instanceof CceconActual) ) return false;
CceconActual castOther = (CceconActual) other;
return new EqualsBuilder()
.append(this.getCceconActualId(), castOther.getCceconActualId())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getCceconActualId())
.toHashCode();
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 02, 2005 4:26 pm 
Newbie

Joined: Wed Jun 01, 2005 4:37 pm
Posts: 3
This is geared toward reporting. Now I tried the following: I created a view to get rid of the foreign key and query the view instead of the original table I got the same errors: Attribute "callable" is not declared for element "sql-query", org.hibernate.MappingException: invalid mapping.

My intension is to query using hibernate named query through stroed procedure, but use hibernate POJO for transfer objects. I think this is a quite typical use case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.