I am trying to learn a bit more on Object Oriented Programming.
In this exercise, I do not want to use any Containercontainer such as Spring or Glassfish. I am deploying my application to Tomcat. I only use JPA. What I want to achieve is to follow best practices and OOP Conceptsconcepts correctly, and a good separation of concerns and layering.
Let me add my code here, I have a database table like this:
and here is my EntityEntity
:
This is my PersistenceUtilPersistenceUtil
class:
and in my Web Applicationweb application I have a ContextListenerContextListener
:
#2 Is it ok that the DAO Layer requires an EntityManagerEntityManager
and assumes that its transaction has already begun? Should it be the DAOs responsibility to obtain the EntityManagerEntityManager
and/or begin/commit transaction?
#3 Again, I have the same questions on my mind. Is this class a mess like this? It does not have any dependencies, it obtains its EntityManagerEntityManager
from the PersistenceUtilPersistenceUtil
class in the Constructor. Is this ok? How about the entityManagerentityManager
field and starting / committing transactions which surrounds DAO calls?
#4 Is it ok that the Servlet initialises a Service ObjectService
object for each call? Or should it have a private static Service object?(I think not, but I am not sure thus asking..)
Thank you very much for your time.