Hibernate 2.6
With all requisite disclaimers acknowledging the silliness of
non-unique keys...
I am stuck with a legacy table with non-unique keys. (The mapping follows).
The table is keyed with a composite id which is not unique. Basically, there
may be multiple time-stamped entries that serve as descriptive lines for
a transaction detailed in another table.
When I do a query the size of results List is correct. However, when I
look at the records the one field (ie. description) that is not part of the composite id
is the same in all the records.
Originally, I was depending on default auto-generated (hbm2java) equals()
implementation which used only the fields within the id. It occurred to me
that this may not work because hibernate would not be able to
distinguish between cached entities that are different though they have the
same key.
I then added the 'description' field (the only non-key field) to the equals()
implementation (using use-in-equals) but this did not change a thing.
I have tried querying with both HQL within the mapping file as below
(ie. getCashHistoryDetailDescriptionsById) and using a Criteria object
which mimics the HQL below.
Am I doing something wrong? Given that I am stuck with table,
is there are workaround?
Thanks
Rob
Code:
<?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="com.trustetc.model.CashHistoryDetailDescription"
table="TRDHISS" >
<meta attribute="class-description" inherit="false">
@hibernate.class
table="TRDHISS"
</meta>
<composite-id name="id"
class="com.trustetc.model.CashHistoryDetailDescriptionID" >
<meta attribute="field-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
<meta attribute="use-in-equals">true</meta>
<key-property
name="accountNumber"
column="TAN"
type="int"
length="7"
>
<meta attribute="field-description">
@hibernate.property
column="TAN"
</meta>
</key-property>
<key-property
name="postDate"
column="PDATE"
type="int"
>
<meta attribute="field-description">
@hibernate.property
column="PDATE"
</meta>
</key-property>
<key-property
name="userId"
column="USERID"
type="java.lang.String"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="USERID"
</meta>
</key-property>
<key-property
name="postTime"
column="PTIME"
type="int"
length="6"
>
<meta attribute="field-description">
@hibernate.property
column="PTIME"
</meta>
</key-property>
</composite-id>
<property
name="description"
column="DESC"
type="java.lang.String"
length="35"
>
<meta attribute="field-description">
@hibernate.property
column="DESC"
</meta>
<meta attribute="use-in-equals">true</meta>
</property>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
</class>
<query name="allCashHistoryDetailDescription">
<![CDATA[from CashHistoryDetailDescription]]>
</query>
<query name="getCashHistoryDetailDescription">
<![CDATA[from CashHistoryDetailDescription c where c.id.accountNumber = :accountNumber order by c.id.postDate desc ]]>
</query>
<query name="getCashHistoryDetailDescriptionsById">
<![CDATA[from CashHistoryDetailDescription c where c.id.accountNumber = :accountNumber and c.id.userId = :user and c.id.postDate = :pdate and c.id.postTime = :ptime order by c.id.postDate desc ]]>
</query>
</hibernate-mapping>