I'm not positive, but I think Hibernate requires you to have "PK" classes for compound primary keys (at least that is always the way I have used it when I can't get away from the evils of compound keys).
One thing that might help you though to expand on my example is that you can provide "helper" methods on the domain objects like so:
Code:
public class BankAccount {
private Id _id;
private String _name;
public static class Id implements Serializable {
private String _bankAccountNumber;
private String _bankAbaNumber;
/**
* @hibernate.property column="BANK_ACCT_NUM"
*/
public String getBankAccountNumber() { ... }
/**
* @hibernate.property column="BANK_ABA_NUM"
*/
public String getBankAbaNumber() { ... }
//.... setters, and must implement equals and hashCode
}
/**
* @hibernate.id class="BankAccount$Id" generator-class="assigned"
*/
public Id getId() { return _id; }
/**
* @hibernate.property column="NAME"
*/
public String getName() { return _name}
public String getBankAccountNumber() {
return _id == null ? null : _id.getBankAccountNumber();
}
public String getBankAbaNumber() {
return _id == null ? null : _id.getBankAbaNumber();
}
//....
}
At least this approach makes the internal id classes transparent to most application code. You can also provide helpers on the setter methods if you want.
It's a bit of a pain, but then again so are a lot of things when dealing with tables with compound primary keys.