I'm using Hibernate as the DAO within a Spring business tier.
For one 'findQuery' call the resultant list contains 3 times the number of records that actually exist, i.e. there are 7 records, and the query is returning 21 ( i.e. 3 instances of each real record).
Code:
private final static String ANALYSIS = "Analysis";
private final static String ANALYSIS_PATH = "com.eis.risk.analysis." + ANALYSIS;
String aQuery = "from " + ANALYSIS_PATH + " as model order by model." + ANALYSIS_TITLE;
List aList = getHibernateTemplate().find(aQuery); // returns 21 records - when it should be 7
The situation is complicated by the fact that I have three Hibernate mappings onto this single table, and I'm wondering if this the cause.
The first mapping 'Rma.hbm.xml' - maps to the main table itself. This is the mapping used on my call that is returning the 21 records. The second mapping 'RmaInfo.hbm.xml' links in two associated tables to bring back status info as a composite object. The third mapping 'RmaPlus.hbm.xml' links in a host of tables to bring back lots of subordinate data.
The second mapping type 'RmaInfo.hbm.xml' would have been called prior to my call that uses 'Rma.hbm.xml'. Is the latter picking up cached data from the earlier call?
Any ideas?
Here are the class definitions and hbm files....
----oOo---
First the start of the class definition...
Code:
public class Analysis extends AliasNamedEntity implements Serializable {
private static final long serialVersionUID = -644896087713571799L;
private String fProjectID = null;
private int fCurrencyID = ID_UNASSIGNED;
private int fCurrencyRateTypeID = ID_UNASSIGNED;
private int fVersion = ID_UNASSIGNED;
private boolean fUseAliasFormat = false;
private int fAliasFormatID = ID_UNASSIGNED;
... and the related Hibernate mapping...
Rma.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.eis.risk.analysis.Analysis" table="rma">
<id name="ID" type="java.lang.Integer" unsaved-value="-1">
<column name="RmaID" />
<generator class="native" />
</id>
<version name="version" column="RmaVersion"/>
<property name="title" type="java.lang.String">
<column name="RmaTitle" length="50" />
</property>
<property name="alias" type="java.lang.String">
<column name="RmaAlias" length="20" not-null="true" unique="true" />
</property>
<property name="desc" type="java.lang.String">
<column name="RmaDesc" length="65535" />
</property>
<property name="projectID" type="java.lang.String">
<column name="ProjectID" />
</property>
<property name="currencyID" type="java.lang.Integer">
<column name="CurrencyID" not-null="true" />
</property>
<property name="currencyRateTypeID" type="java.lang.Integer">
<column name="CurrencyRateTypeID" not-null="true" />
</property>
<property name="useAliasFormat" type="java.lang.Boolean">
<column name="RmaUseAliasFormat" />
</property>
<property name="aliasFormatID" type="java.lang.Integer">
<column name="AliasFormatID" />
</property>
</class>
</hibernate-mapping>
----oOo---
The start of the class definition...
Code:
public class AnalysisInfo extends Analysis {
private static final long serialVersionUID = -6216981111520585437L;
private AnalysisStatusPoint fLatestStatus;
private AnalysisLock fLock;
... and the related Hibernate mapping...
RmaInfo.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.eis.risk.analysis.AnalysisInfo" table="rma">
<id name="ID" type="java.lang.Integer" unsaved-value="-1">
<column name="RmaID" />
<generator class="native" />
</id>
<version name="version" column="RmaVersion"/>
<property name="title" type="java.lang.String">
<column name="RmaTitle" length="50" />
</property>
<property name="alias" type="java.lang.String">
<column name="RmaAlias" length="20" not-null="true" unique="true" />
</property>
<property name="desc" type="java.lang.String">
<column name="RmaDesc" length="65535" />
</property>
<property name="projectID" type="java.lang.String">
<column name="ProjectID" />
</property>
<property name="currencyID" type="java.lang.Integer">
<column name="CurrencyID" not-null="true" />
</property>
<property name="currencyRateTypeID" type="java.lang.Integer">
<column name="CurrencyRateTypeID" not-null="true" />
</property>
<property name="useAliasFormat" type="java.lang.Boolean">
<column name="RmaUseAliasFormat" />
</property>
<property name="aliasFormatID" type="java.lang.Integer">
<column name="AliasFormatID" />
</property>
<join table="rma_latest_status_point">
<key column="RmaID" unique="true"/>
<many-to-one name="latestStatus"
column="PointID" not-null="true" unique="true" lazy="false"/>
</join>
<join table="rma_lock" optional="true">
<key column="RmaID" unique="true" />
<many-to-one name="lock" class="com.eis.risk.analysis.AnalysisLock"
column="RmaLockID" unique="true" lazy="false"/>
</join>
</class>
</hibernate-mapping>
----oOo---
The start of the class definition...
Code:
public class AnalysisPlus extends Analysis {
private static final long serialVersionUID = -4637247788793525640L;
private Set<FolderEntry> fFolderEntries = new HashSet<FolderEntry>();
private Set<LatestPointLink> fLatestPointLink = new HashSet<LatestPointLink>();
private Set<AnalysisLock> fLocks = new HashSet<AnalysisLock>();
private Set<AnalysisStatusPoint> fStatusPoints = new HashSet<AnalysisStatusPoint>();
private Set<RiskEntryPlus> fRiskEntries = new HashSet<RiskEntryPlus>();
... and the related Hibernate mapping...
Code:
[B]RmaPlus.hbm.xml[/B]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.eis.risk.analysis.AnalysisPlus" table="rma">
<id name="ID" type="java.lang.Integer" unsaved-value="-1">
<column name="RmaID" />
<generator class="native" />
</id>
<version name="version" column="RmaVersion"/>
<property name="title" type="java.lang.String">
<column name="RmaTitle" length="50" />
</property>
<property name="alias" type="java.lang.String">
<column name="RmaAlias" length="20" not-null="true" unique="true" />
</property>
<property name="desc" type="java.lang.String">
<column name="RmaDesc" length="65535" />
</property>
<property name="projectID" type="java.lang.String">
<column name="ProjectID" />
</property>
<property name="currencyID" type="java.lang.Integer">
<column name="CurrencyID" not-null="true" />
</property>
<property name="currencyRateTypeID" type="java.lang.Integer">
<column name="CurrencyRateTypeID" not-null="true" />
</property>
<property name="useAliasFormat" type="java.lang.Boolean">
<column name="RmaUseAliasFormat" />
</property>
<property name="aliasFormatID" type="java.lang.Integer">
<column name="AliasFormatID" />
</property>
<set name="folderEntries" lazy="true" cascade="delete">
<key column="rmaID" />
<one-to-many class="com.eis.risk.analysis.FolderEntry"/>
</set>
<set name="latestPointLink" lazy="true" cascade="delete">
<key column="rmaID" />
<one-to-many class="com.eis.risk.analysis.LatestPointLink"/>
</set>
<set name="locks" lazy="true" cascade="delete">
<key column="rmaID" />
<one-to-many class="com.eis.risk.analysis.AnalysisLock"/>
</set>
<set name="statusPoints" lazy="true" cascade="delete">
<key column="rmaID" />
<one-to-many class="com.eis.risk.analysis.AnalysisStatusPoint"/>
</set>
<set name="riskEntries" lazy="true" cascade="delete">
<key column="rmaID"/>
<one-to-many class="com.eis.risk.entry.RiskEntryPlus"/>
</set>
</class>
</hibernate-mapping>
----oOo---