Database access in Struts -- best/common practice?
posted 13 years ago
I have seen many Struts example applications, and the database layer is always different -- some use Torque, others use JDBC calls within the FormBean. What is the most common solution? I am not using EJB's, and I understand that Struts is designed in such a way that you can use any data model...but in all methodologies there always seems to be the solution that works 90% of the time....any suggestions?
The best practice I've seen is to ensure complete seperation between the classes that access the database and Struts. In general, the best practice is to have DataAccessObjects (DAOs) access the database directly (and therefore hide the database interface completely from your application). These in turn should be called from a business object layer. Then the Struts Actions will talk to these business objects. That is by far the best layered approach.