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();
}
}