Hey there, I’m new user of Hibernate.
I have a question regarding annotations. I would like to annotate some of my entities so Hibernate knows how to persist them correctly.
My question is: should I annotate my business classes directly? Or should I rather create simple classes just with getters / setters and without any complex logic which would represent real DB structure?
I think the latter approach is more clean, but on the other hand that would require to create special converters between those two classes (business => simple and vice versa).
This strongly depends on how you want to work with you persistence technology. Some people prefer encapsulation and others use domain types as entities directly. I personally prefer separation of concerns because sometimes you can’t model things you’d like to have in the persistence model. Apart from that, the persistence model is usually a 1:1 object model mapping of the database, but rich application usually have demands that span multiple domain types e.g. aggregations/projections which can’t be modeled well with a persistence model that is a 1:1 mapping of the database.
For the conversion between the two models I can recommend you take a look at what Blaze-Persistence Entity-Views has to offer, as that can also help you get the best performance out of such a separation.