Hi Erik
Thanks for replying. Unfortunately, Hibernate returns more than one record back for a primary key ... I solved this problem by
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
This is happened in other instances in my project also. It could be a bug
in 2.1. Please note that I have been using Hibernate for one year now.
Thanks
Ron
Here is the code:
---------------------------
try {
Session session = HibernateUtil.getSession();
Criteria criteria = session.createCriteria( ActionPlan.class );
criteria.add( Expression.eq( "actionPlanId", key ) );
finds = criteria.list();
if ( finds.size() > 1 ) {
throw new DAOException( "There is currently more than one active record in the system with id [" + key + "]");
}
if ( finds.size() < 1 ) {
throw new DAOException( "There is currently no active record in the system with id [" + key + "]");
}
} catch ( HibernateException he ) {
String message = "Failed to perform findByPkDeepReview for [ActionPlan]";
log.error( message, he );
throw new DAOException( message , he );
} finally {
HibernateUtil.closeSession();
}
-------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class name="gov.hud.cpd.drgr.business.ActionPlan" table="ACTION_PLAN" >
<meta attribute="implement-equals" inherit="false">true</meta>
<id name="actionPlanId" type="java.lang.Long" column="ACTION_PLAN_ID" >
<meta attribute="use-in-equals">true</meta>
<generator class="sequence">
<param name="sequence">ACTION_PLAN_ID</param>
</generator>
</id>
<property name="planDescription" type="java.lang.String" column="PLAN_DESCRIPTION" length="4000" >
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<property name="hqDispositionDate" type="java.sql.Timestamp" column="HQ_DISPOSITION_DATE" length="7" >
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<property name="insertTimestamp" type="java.sql.Timestamp" column="INSERT_TIMESTAMP" length="7" >
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<property name="lastUpdateTimestamp" type="java.sql.Timestamp" column="LAST_UPDATE_TIMESTAMP" length="7" >
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<property name="rowStatusId" type="java.lang.Long" column="ROW_STATUS_ID" length="15" >
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<!-- Associations -->
<!-- bi-directional one-to-many association to Activity -->
<set name="activities" lazy="true" inverse="true" cascade="save-update" >
<key column="ACTION_PLAN_ID" />
<one-to-many class="gov.hud.cpd.drgr.business.Activity" />
</set>
<!-- bi-directional one-to-many association to ActionPlanHist -->
<set name="actionPlanHists" lazy="true" inverse="true" cascade="all-delete-orphan" >
<key column="ACTION_PLAN_ID" />
<one-to-many class="gov.hud.cpd.drgr.business.ActionPlanHist" />
</set>
<!-- bi-directional one-to-many association to Qpr -->
<list name="qprs" lazy="true" inverse="true" cascade="none" >
<key column="ACTION_PLAN_ID" />
<index column="POSITION"/>
<one-to-many class="gov.hud.cpd.drgr.business.Qpr" />
</list>
<!-- bi-directional one-to-many association to ActionPlanFunding -->
<set name="actionPlanFundings" lazy="true" inverse="true" cascade="all-delete-orphan" >
<key column="ACTION_PLAN_ID" />
<one-to-many class="gov.hud.cpd.drgr.business.ActionPlanFunding" />
</set>
<list name="actionPlanNeeds" lazy="false" table="ACTION_PLAN_NEED" outer-join="true" >
<key column="ACTION_PLAN_ID" />
<index column="POSITION"/>
<element type="string" column="NEED_DESCRIPTION" not-null="true" />
</list>
<!-- bi-directional one-to-many association to ActionPlanReviewHist -->
<set name="actionPlanReviewHists" lazy="true" inverse="true" cascade="all-delete-orphan" order-by="REVIEW_DATE" >
<key column="ACTION_PLAN_ID" />
<one-to-many class="gov.hud.cpd.drgr.business.ActionPlanReviewHist" />
</set>
<!-- bi-directional many-to-one association to Grant -->
<many-to-one name="grant" class="gov.hud.cpd.drgr.business.Grant" not-null="true" >
<meta attribute="use-in-equals">true</meta>
<column name="GRANTS_ID" />
</many-to-one>
<many-to-one name="reviewStatus" column="REVIEW_STATUS_ID" class="gov.hud.cpd.drgr.business.ReviewStatus" not-null="true" />
<!-- bi-directional many-to-one association to Grantee -->
<many-to-one name="grantee" class="gov.hud.cpd.drgr.business.Grantee" not-null="true" >
<meta attribute="use-in-equals">true</meta>
<column name="GRANTEE_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to User -->
<many-to-one name="userByLastUpdateUserId" class="gov.hud.cpd.drgr.business.User" not-null="true" >
<meta attribute="use-in-equals">true</meta>
<column name="LAST_UPDATE_USER_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to User -->
<many-to-one name="userByInsertUserId" class="gov.hud.cpd.drgr.business.User" not-null="true" >
<meta attribute="use-in-equals">true</meta>
<column name="INSERT_USER_ID" />
</many-to-one>
</class>
</hibernate-mapping>