Hi,
I'm using hibernate version 2.1 with OSCache for process level caching. Using MS SQL. Till now, I was using it to cache objects with a single key and it worked. Now I'm trying to cache an object with a composite key and it fails and instead retrieves the data from the db all the time. I have put some debug statements and I don't see the 'equals' method on the key object (FqmTaskPK) being invoked.
Listed below is the Java code (for the object that I'm attempting to cache), hbm.xml file auto generated by middlegen.
Appreciate your help.
Regards,
Jiten
package com.test;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class FqmTaskPK implements Serializable {
/** identifier field */
private String id;
/** identifier field */
private String businessId;
/** full constructor */
public FqmTaskPK(String id, String businessId) {
this.id = id;
this.businessId = businessId;
}
/** default constructor */
public FqmTaskPK() {
}
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
/**
* @hibernate.id
* generator-class="assigned"
*
*/
public String getBusinessId() {
return this.businessId;
}
public void setBusinessId(String businessId) {
this.businessId = businessId;
}
public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.append("businessId", getBusinessId())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof FqmTaskPK) ) return false;
FqmTaskPK castOther = (FqmTaskPK) other;
return new EqualsBuilder()
.append(this.getId(), castOther.getId())
.append(this.getBusinessId(), castOther.getBusinessId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getId())
.append(getBusinessId())
.toHashCode();
}
}
hbm.xml
<?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 Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.test.FqmTask"
table="fqm_task"
>
<meta attribute="field-description">
@hibernate.class
table="fqm_task"
</meta>
<cache usage="nonstrict-read-write"/>
<composite-id name="comp_id" class="com.hp.goit.fqm.model.FqmTaskPK">
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
</meta>
<key-property
name="id"
column="id"
type="java.lang.String"
length="50"
/>
<key-property
name="businessId"
column="business_id"
type="java.lang.String"
length="50"
/>
</composite-id>
<property
name="name"
type="java.lang.String"
column="name"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="name"
length="50"
</meta>
</property>
<property
name="role"
type="java.lang.String"
column="role"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="role"
length="50"
</meta>
</property>
<!-- associations -->
<!-- bi-directional one-to-many association to FqmActionCod -->
<set
name="fqmActionCods"
lazy="true"
inverse="true"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
inverse="true"
@hibernate.collection-key
column="action_id"
@hibernate.collection-key
column="business_id"
@hibernate.collection-one-to-many
class="com.hp.goit.fqm.model.FqmActionCod"
</meta>
<cache usage="nonstrict-read-write"/>
<key>
<column name="action_id" />
<column name="business_id" />
</key>
<one-to-many
class="com.hp.goit.fqm.model.FqmActionCod"
/>
</set>
</class>
</hibernate-mapping>