max wrote:
hibernate can't inject via the constructor so if you want the property to be loaded from the database it need to be set *somehow*
Many software design gurus advocate using immutability where possible and Hibernate states it is transparent to the domain model. If immutability according to Hibernate means making all setters private (without using final keyword), then fine.
Hang on a sec... In Cavet Emptor final fields are used:
Code:
public class MonetaryAmount implements Serializable {
private final BigDecimal amount;
private final Currency currency;
public MonetaryAmount(BigDecimal amount, Currency currency) {
this.amount = amount;
this.currency = currency;
}
Ah, that's why MonetaryAmountSimpleUserType.java is also present.
Ironicly, there is comment to this in the book:
Quote:
We have made MonetaryAmount an immutable class. This is a good practice in Java
because it simplifies coding.
With all due respect, needing to write a new custom UserType for each immutable class doesn't sound too simple.
I wounder if there was some other solution for using final fields, e.g. reflexion or ... advanced reflexion )