camilosaurio wrote:
1) The invoice table has a field called total that is simply the sum of the total of each detail. In my application objects I don't want to have this value, since I can calculate it and avoid inconsistency problems. However, when I insert a new invoice, I have to write this value to the database. I have a getTotal method, but hibernate does not consider it a valid property since it does not have the corresponding setTotal method. Is there a way to map the column and make hibernate get the total from the getTotal method creating this method on the object?
I think you could have a look at the formula tag in the mapping. If hibernate is requesting the setTotal but you do not want to provide it publicly, you could define it with protected visibility, Hibernate will still be able to use it. In general, put protected everything you can that's specific to hibernate, but that you would prefer not exposing as a public API.
camilosaurio wrote:
2) There are some other columns in the database I don't want to map. However this columns are declared not null, so I would like to simply fill them with '0'. Is there a way to make hibernate insert a constant to this columns without creating a property for them in the object?
I guess a formula could do the trick here.