Should Enterprise Java entities be dumb?
I think your point is valid.
See this for more - http://martinfowler.com/bliki/AnemicDomainModel.html
With JPA, the Entities are light-weight objects. So I don't think its any problem having logic in them.
In case of use with SOAP/Web Services, I'd add a separate Facade Layer.
The DTO and VO are supposed to be used to transfer data and don't embed logic. The business objects on the other hand are supposed to embed some logic. I say some, because there is always a balance to find between what you put in services which coordinate logic involving several business objects and what you put in the business objects themselves. Typical logic in the business objects can be validation, field computation, or other operation that impact only one business object at a time.
Note that I haven't mentioned the term entity so far. Persistent entities were popularized with ORM and we nowadays try to use persistent entities both as DTO and business object at the same time. That is, the entity themselves flow between layers and tiers, and contain some logic.
Are there any more valid reasons not to move logic into my entities? Or any other concerns to take into account?
As you pointed out, it's all a matter of dependencies and what you expose. As long as the entities are dumb (close to DTO) they can be isolated in a dedicated jar easily that serves as API of the layer. The more logic you put in the entities, the harder it becomes to do that. Pay attention to what you expose and what you depend on (the load the class, the client will need to have the depend class as well). This applies to exceptions, inheritance hierarchy, etc.
Just to give an example, I had a project where the entities had a method toXml(...)
used in the business layer. As a consequence, client of the entities depended on XML.
But if you don't care too much about layers, and strict separation between API and implementation, I think it's good to move some logic in the entities.
EDIT
This question has been discussed many time and will probably continue to be discussed as there is no definitive answer. A few interesting links:
- Getter Eradicator
- Anemic domain model
- The importance of being closed
- Domain Modeling
- Where does my business logic go?
- Transfer object vs. business object