-->
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: Hibernate Mapping - Stored Proc result from multiple tables
PostPosted: Thu Oct 22, 2009 1:18 pm 
Newbie

Joined: Thu Oct 22, 2009 12:37 pm
Posts: 3
Hibernate 3.0 & MS SQL 2005

I have a stored procedure that gives values from multiple tables. This procdure returns these values in a reslut set. The result set return does not map to a specific table in the db. can i map this result set to an entity in the mapping file? If im not mapping to a table how can I leave out the class element, id element and property elements? is this possible?

<?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>
<class name="com.cynosure.sf.domain.ForecastFilter">
<property name="managerId" type="short">
<column name="COLUMN1"/></property>
<property name="price" type="java.math.BigDecimal">
<column name="COLUMN2"/></property>
<property name="forecast" type="java.math.BigDecimal">
<column name="COLUMN3"/></property>
<property name="pending" type="java.math.BigDecimal">
<column name="COLUMN4"/></property>
<property name="booked" type="java.math.BigDecimal">
<column name="COLUMN5"/></property>
</class>
<sql-query name="mrgviewSP" callable="true">
<return alias="mrgviewSP" class="com.cynosure.sf.domain.ForecastFilter">
<return-property name="managerId" column="manager"/>
<return-property name="price" column="price"/>
<return-property name="forecast" column="forecast"/>
<return-property name="pending" column="pending"/>
<return-property name="booked" column="booked"/>
</return>
EXEC mrgviewSP :para1, :para2, :para3, :para4, :para5, :para6, :para7, :para8, :para9, :para10, :para11 ) }
</sql-query>

</hibernate-mapping>

--------------Java Code ---------------
List list = null;
try {

Session session = HibernateUtils.currentSession();
Query query = session.getNamedQuery("mrgviewSP");
query.setParameter("para1", obj1 );
query.setParameter("para2", obj2 );
query.setParameter("para3",obj3 );
query.setParameter("para4", obj4 );
query.setParameter("para5",obj5 );
query.setParameter("para6",obj6 );
query.setParameter("para7",obj7 );
query.setParameter("para8",obj8);
query.setParameter("para9",obj9 );
query.setParameter("para10",obj10);
query.setParameter("para11", obj11 );

list = query.list();

HibernateUtils.closeSession();


----------------------POJO----------------
public class ForecastFilter implements java.io.Serializable{

private Short managerId;
private Short price;
private BigDecimal forecast;
private BigDecimal pending;
private BigDecimal booked;

public ForecastFilter(Short managerId, Short price, BigDecimal forecast,
BigDecimal pending, BigDecimal booked) {
super();
this.managerId = managerId;
this.price = price;
this.forecast = forecast;
this.pending = pending;
this.booked = booked;
}

public Short getManagerId() {
return managerId;
}
public void setManagerId(Short managerId) {
this.managerId = managerId;
}
public Short getPrice() {
return price;
}
public void setPrice(Short price) {
this.price = price;
}
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;
}
}

Errors :-

SEVERE: Error parsing XML: XML InputStream(17) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".


Can any one please help me in finding a solution .


Thanks,
Sakula


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.