In our legacy Java EE application, there are loads of value object (VO) classes which typically contain only getters and setters, maybe equals()
and hashCode()
. These are (typically) the entities to be saved in persistence storage. (For the record, our app has no EJBs - although that might change in the future -, and we use Hibernate for persisting our entities.) All the business logic to manipulate the data in VOs is in separate classes (not EJBs, just POJOs). My OO mindset hates this, as I do believe that the operations on a given class should reside in that same class. So I have an urge to refactor to move logic into the related VOs.
I just had a discussion with a co-worker who is much more experienced in Java EE than me, and he confirmed that dumb entities at least used to be the recommended way to go. However, he has also read opinions recently which question the validity of this stance.
I understand that there are issues which at least limit what can be put inside an entity class:
- it should not have direct dependency to the data layer (e.g. query code should rather go into separate DAOs)
- if it is directly exposed to higher layers or to the client (e.g. via SOAP), its interface may need to be limited
Are there any more valid reasons not to move logic into my entities? Or any other concerns to take into account?