Hello,
I have the following table structure:
Code:
ACCOUNTS
ID : VARCHAR(32) PK
TYPE : CHAR(1)
BALANCES
ACCOUNT_ID : VARCHAR(32) PK
CURRENCY : CHAR(3) PK
BALANCE : NUMERIC(16,2)
In other words there are accounts which can have balances in several currencies. The BALANCES table's primary key consists of two fields.
I have an Account class:
Code:
/**
* @hibernate.class table="ACCOUNTS"
*/
public class Account {
private String id;
private char type;
private Set balances;
/**
* @hibernate.id generator-class="assigned"
*/
public String getId() { return id; }
public void setId(String id) { this.id = id; }
/**
* @hibernate.property
*/
public char getType() { return type; }
public void setType(char type) { this.type = type; }
/**
* @hibernate.set
* @hibernate.collection-key column="ACCOUNT_ID"
* @hibernate.collection-???????
*/
public Set getBalances() { return balances; }
public void setBalances(Set balances) { this.balances = balances; }
}
And a Balance class:
Code:
public class Balance {
private String currency;
private BigDecimal amount;
public String getCurrency() { return currency; }
public void setCurrency(String currency) { this.currency = currency; }
public BigDecimal getAmount() { return amount; }
public void setAmount(BigDecimal amount) { this.amount = amount; }
}
And the question is what do I write in place of the question marks in the Account.getBalances() javadoc?
Initially I thought that one-to-many would be great but as the PK for BALANCES table is in two fields then I would probably have to add the accounId field to Balance class?
Another option I thought of was using the Balance as a component. This means I should implement equals() and hashCode() in Balance. In the equals method - would it be ok to compare the values of the currency fields?
Are there any other possibilities?
Any advice would be greatly appreciated,