I'm developing a Java/Spring/Hibernate application that adheres to the CQS (Query Command Separation) pattern.
Put simply:
- our
domain modelis only used byCommandswhich describe some operation that needs to be done on the domain model; - all read operations are done by a
QueryServicethat bypasses thedomain modelso it can optimise (usingprojection) each query on a use case basis.
The domain model maps to MySQL database by using Hibernate.
I know there's a longrunning debate about separation between domain and persistence model. However, I'm convinced that nowadays Hibernate has become so flexible that you don't have to make hard sacrificies on the domain model. This way, you don't get a one-to-one mapping between domain and persistence model. Additionally, all DB-related stuff can be abstracted away by using Layer Supertypes.
My questions:
- If I use
HibernateQuery(orCriteria) using projection in myQueryService, I'm in fact using my domain model instead of plain SQL. Isn't this a breach against theCQSpattern...? - I could opt for using plain SQL in my
QueryService. Is there any good SQL framework out there that gives me the possibility to build Queries without using domain model AND easily binding results into JavaBeans? The results are typically graphs, so it would be nice to easily bind these to some nested JavaBean structure.