I'm having trouble with the Interceptor on a composite-element in a map. I have the following mapping:
Code:
<hibernate-mapping>
<class
name="com.termnetinc.domain.merchant.MerchantLocationBaseImpl"
table="MERCHANT_LOCATION"
optimistic-lock="version"
>
<id
name="merchantId"
type="long"
column="MERCHANT_ID"
>
<generator class="sequence">
<param name="sequence">merchant_location_sequence</param>
</generator>
</id>
<version
column="tuple_version"
name="persistentVersion"
type="long"
unsaved-value="undefined"
/>
<map
name="bankAccountsPersistent"
table="MERCHANT_BANK_ACCOUNT"
lazy="false"
inverse="false"
cascade="all"
>
<key column="MERCHANT_ID"/>
<index-many-to-many
column="TYPE_ID"
class="com.termnetinc.domain.merchant.BankAccountTypeBaseImpl"
/>
<composite-element
class="com.termnetinc.domain.merchant.BankAccountBaseImpl"
>
<property
name="routingNumber"
type="long"
column="ROUTING_NUMBER"
not-null="true"
length="9"
/>
<property
name="accountNumber"
type="java.lang.String"
column="ACCOUNT_NUMBER"
not-null="true"
length="17"
/>
</composite-element>
</map>
BankAccountBaseImpl.java is the class in question:
Code:
public class BankAccountBaseImpl
implements BankAccount
{
private static final int HASH_CODE_INITIAL = 31;
private static final int HASH_CODE_MULTIPLIER = 7;
private String accountNumber;
private long routingNumber;
public String getAccountNumber()
{
return this.accountNumber;
}
public long getBankAccountId()
{
return this.bankAccountId;
}
public long getRoutingNumber()
{
return this.routingNumber;
}
public boolean equals(final Object compare)
{
if(!(compare instanceof BankAccountBaseImpl))
{
return false;
}
BankAccountBaseImpl compareImpl = (BankAccountBaseImpl) compare;
EqualsBuilder builder = new EqualsBuilder();
builder.append(this.accountNumber, compareImpl.accountNumber);
builder.append(this.routingNumber, compareImpl.routingNumber);
return builder.isEquals();
}
public int hashCode()
{
HashCodeBuilder builder = new HashCodeBuilder(HASH_CODE_INITIAL, HASH_CODE_MULTIPLIER);
builder.append(this.accountNumber);
builder.append(this.routingNumber);
return builder.toHashCode();
}
public String toString()
{
ToStringBuilder builder = this.getStringBuilderUtils().getObjectToStringBuilder(this);
builder.append("accountNumber", this.accountNumber);
builder.append("routingNumber", this.routingNumber);
return builder.toString();
}
public void setAccountNumber(final String accountNumber)
{
this.accountNumber = accountNumber;
}
public void setRoutingNumber(final Long routingNumber)
throws IllegalStateException
{
this.routingNumber = routingNumber.longValue();
}
}
I have the following Interceptor defined:
Code:
public class ObjectInterceptor implements Interceptor
{
public ObjectInterceptor()
{
}
public int[] findDirty
( final Object obj
, final Serializable serializable
, final Object[] obj2
, final Object[] obj3
, final String[] str
, final Type[] type
)
{
// do nothing
return null;
}
public Object instantiate
( final Class clazz
, final Serializable serializable
) throws CallbackException
{
return null;
}
public Boolean isUnsaved(final Object obj)
{
// do nothing
return null;
}
public void onDelete
( final Object obj
, final Serializable serializable
, final Object[] obj2
, final String[] str
, final Type[] type
) throws CallbackException
{
// do nothing
}
public boolean onFlushDirty
( final Object obj
, final Serializable serializable
, final Object[] obj2
, final Object[] obj3
, final String[] str
, final Type[] type
) throws CallbackException
{
// do nothing
return false;
}
public boolean onLoad
( final Object obj
, final Serializable serializable
, final Object[] obj2
, final String[] str
, final Type[] type
) throws CallbackException
{
System.out.println("loading instance of " + obj.getClass().getName() + ": " + obj.hashCode());
return false;
}
public boolean onSave
( final Object obj
, final Serializable serializable
, final Object[] obj2
, final String[] str
, final Type[] type
) throws CallbackException
{
// do nothing
return false;
}
public void postFlush(final Iterator iterator) throws CallbackException
{
// do nothing
}
public void preFlush(final Iterator iterator) throws CallbackException
{
// do nothing
}
}
Everything persists as expected. When I rehydrate, the Interceptor onLoad method is called for every Hibernate object except the composite-element in the map. Is this the expected behavior? If so, I'm curious as to why composite-elements don't get passed to onLoad, and if there a workaround to allow me to capture the loading of these as with other objects?