I am creating a web application that lets the user store and retrieve information from a DB through a GUI using spring and hibernate.
I have gotten stuck when it comes to creating the DAO and service layer. I want to create a method that can add a new delivery. In my delivery table i have Product Id and Customer Id which both are mapped to their own tables that contain Product Name, Product Type and Customer Name, Customer Country respectively.
The part that I have trouble with is that I want the end user to record a delivery by entering the product type, product name, customer name, customer country and date. Do I,
(1) Create a DAO with a method for adding a new delivery that includes these objects
or
(2) Create a DAO that just persist a general object to the DB and then use a service method to implement the DAO for each separate object?
Thank you for your help!
/D
here is a snippet of my generic dao, which I inject into each service layer class.
Which can hen be used in your service layer like so :
And of course you could extend the dao for specific complex queries. Having one generic dao obeys single point of responsibility principle, DRY, and makes it easier to test. The transactions should be on serivce layer and directly relate to units of work.