Well..
Let me express my feelings again, in a shorter and neater way.
DAOs are to be dismissed, because they solve a problem of data accessing. For example returnin objects from JDBC. When a platform like Roo is JPA based, the DAOs are a redundancy.
The service layer should contain a method havind this signature:
Code:
public void persist(Object o)
rather than:
Code:
public void persistBook(Book b);
public void persistAuthor(Author a);
My way (the former) introduces no code duplication.
Look at what the aspects contain. Every entity contains:
Code:
@Transactional
public void EntityClass.persist() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.persist(this);
}
Is this a cool thing ?
The fact that a tool generates code for you, and that code is placed in files implementing something called "aspects", is not "separation of concerns" necessarily.
All aspects generated by Roo contain duplicate code among themselves. Thats bad.
Look at the body of the above method. Thats wrong. The right thing is:
Code:
public class ServiceManager {
@PersistenceContext
EntityManager em;
@Transactional
public void persist(Object o){
em.persist(o);
}
// other, more complex, service methods
}
Entity creation is a business concern. The fact that it shares JPA signature, which in turn is typically considered to be a data access concern, doesnt mean anything.
A record is not something that should know of entity managers etc..
Consider a standalone app that doesnt access entityManagers and uses the entity classes (they are POJO, remember?). Why should those object know about JPA at all ?
In reference to circular code... I don't see it. Nor do I see any code that crosses layer boundaries inappropriately.
Entity instances are not a part of the service layer. Thats all. From this perspective you could see it.
Package circularities are present..
All matter discussed here is like the emperor's new clothes.
Dont get me wrong. Roo's core idea s fine. Its amazing to have something to fulfill one's laziness... BUT.. not in a boilerplate way.
Btw I am not really informed how to make addons.. that would be nice but.. anyway. Things need change. Thats why versions are so common, we dont even notice what they mean. Every piece of software is presumed to be at least "not-perfect". And thats normal.
The point is that Roo and its message is so good, that it deserves to get better. Which comes at the price of overcoming ego and doing the right thing.
An analogy is reproduction in the animal kingdom.
You can reproduce by division where the child inherits all the parent flaws. (like forking, when you fork something, or copy a concept, you start off with all the parents bugs and flaws, just like the active record example I gave.)
You reproduce by sex, where the child inherits all good parts of its parents, and, more importantly, is being born without any parasites.
After all my post got pretty big, huh