Hi,
I have many stored procedures which are mostly 'get'. I am using Hibernate , Spring , Oracle for my application. Problem : I dont want to map the entity to any table in database as it used only for Stored Proc output. But i get error -
org.hibernate.MappingException: Named query not known: notifyI think its because Hibernate did not load the entity ?? If i add @Entity to Entity class, i get error -
org.hibernate.HibernateException: Missing table: NotifyNOTE: Hibernate doc AND most examples i found on net were same - stored procedure only for single table not multiple table.
My code has service layer which call DAO layer
Code:
return notificationDAO.sendNotify(runDate);
DAO implementation code has the following
Code:
return (List<Notify>)getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return session.getNamedQuery("notify")
.setParameter("runDate", runDate).list();
}
});
Code:
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.NamedNativeQuery;
import javax.persistence.Entity;
import org.hibernate.annotations.GenericGenerator;
@Entity
@NamedNativeQuery(
name = "notify",
query = "{? = call notify(:runDate)}",
resultClass=Notify.class,
callable=true)
public class Notify implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private Long id;
private Long contractId;
private String contractName;
private Date transDate;
private Long transAmt;
private String crtUser;
private String userName;
@Id
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name="contract_id")
public Long getContractId() {
return contractId;
}
public void setContractId(Long contractId) {
this.contractId = contractId;
}
@Column(name="contract_name")
public String getContractName() {
return contractName;
}
public void setContractName(String contractName) {
this.contractName = contractName;
}
@Column(name="trans_date")
public Date getTransDate() {
return transDate;
}
public void setTransDate(Date transDate) {
this.transDate = transDate;
}
@Column(name="trans_amt")
public Long getTransAmt() {
return transAmt;
}
public void setTransAmt(Long transAmt) {
this.transAmt = transAmt;
}
@Column(name="current_user")
public String getCrtUser() {
return crtUser;
}
public void setCrtUser(String crtUser) {
this.crtUser = crtUser;
}
@Column(name="user_name")
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
Thanks,
RockerRocker