Scenario:
- Stack: Java, Spring, Hibernate.
- Model: Client-Server Application.
- Pattern: Model-View-Controller (MVC).
The Service Layer classes has three behaviors:
Some services have the business rule within the methods and delegate the persistence to the application. Like:
EntityManager.save(entity);
Some services simply call a database function (passing parameters) Like:
CallableStatement cls = con.prepareCall("{call databaseFunction(args)}");
Some services have methods with both behaviors.
My questions:
- Is there any problem in having application services call - directly - database functions? Is not this considered bad practice? What would be an architecture model applicable to a project like this?
- Is there any problem in having the behavior mix in the same service? Such as transactions and consistency?
- In the case of maintenance, does this encapsulation make it obscure to the developer that he should also change the functions in the database? How to avoid this?
- Does this scenario happen in other applications around the world or was it just an architectural error?