I'm having a difficult time mapping a HashMap property. My class "Account" has a hash map of "Payments", which is another class.
My class looks like this...
Code:
public class Account () {
...
private Map payments = new HashMap();
...
public Map getPayments() {
return this.payments;
}
public void setPayments(Map payments) {
this.payments = payments;
}
}
May mapping files look like this...
Code:
<class name="Account" table="accounts">
...
<map name="payments" table="payments" cascade="all" access="property" >
<key column="account_id"/>
<index column="reference_number" type="string"/>
<one-to-many class="Payment"/>
</map>
</class>
<class name="Payment" table="payments">
...
<property name="referenceNumber" column="reference_number" type="string" length="32" not-null="true" access="field"/>
<property name="paymentAmount" column="payment_amount" type="big_decimal" access="field" />
</class>
In my Account class, when I add a payment, I use the payment reference number as the key for the HashMap, and the payment object itself as the value for the HashMap.
Code:
// Add the payment to the account's list of unapplied credit payments
this.payments.put(payment.getReferenceNumber(), payment);
And in the code that I call to persist the account I do the following...
Code:
// get the hibernate session
Session session = HibernateUtil.getSession();
// Save the parts of the account that are separate objects in the DB
session.save(account.getPayments());
// Save the account
session.save(account);
session.flush();
The call to session.save() with the payments throws the exception: No persister for: java.util.HashMap.
So, I have two questions, 1) given what I've included here, am I doing something seriously wrong to cause the exception? 2) Does Hibernate support persisting maps with a class as the map 'value'?
Any insight or direction is greatly appreciated.