I'm having a hard time finding any kind of answer to this question and was hoping HiA would flesh it out - but, alas, not even HiA went quite far enough. While HiA talks about CompositeUserTypes, it doesn't mention if a CompositeUserType can contain properties of other CompositeUserTypes. HiA uses a "MonetaryAmount" for illustration. I'll base my own example on this. Say I have created a MonetaryAmount and a MonetaryAmountCompositeUserType (just like in HiA). Now I want to create a DebitCredit type:
Code:
public class DebitCredit implements Serializable
{
private MonetaryAmount debit;
private MonetaryAmount credit;
public DebitCredit(final MonetaryAmount debit, final MonetaryAmount credit)
{
this.debit = debit;
this.credit = credit;
}
public DebitCredit() { }
public MonetaryAmount getDebit() { return this.debit; }
protected void setDebit(final MonetaryAmount debit) { this.debit = debit; }
public MonetaryAmount getCredit() { return this.credit; }
protected void setCredit(final MonetaryAmount credit) { this.credit = credit; }
}
Could I define a DebitCreditCompositeUserType for this class? If so, how? I would define two properties in my CompositeUserType ("debit" and "credit"), but Hibernate would need to reserve four fields (two fields for each MonetaryAmount). I'm not quite sure how to handle this in my nullSafeGet/nullSafeSet, or if it is even possible?
Thanks,
Anodos