Skip to main content
edited title
Link
Vogel612
  • 25.3k
  • 7
  • 58
  • 141

Seperation of Concerns and OOP Principles in Java Web App with JPA but no Container Listing Books nicely - a tour through a webapp

edited title
Link
Koray Tugay
  • 1.5k
  • 5
  • 20
  • 44

Is the seperation Seperation of concernsConcerns and injections ok here?OOP Principles in Java Web App with JPA but no Container

deleted 131 characters in body; edited tags
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

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.

I am trying to learn a bit more on Object Oriented Programming.

In this exercise, I do not want to use any Container 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 Concepts 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 Entity:

This is my PersistenceUtil class:

and in my Web Application I have a ContextListener

#2 Is it ok that the DAO Layer requires an EntityManager and assumes that its transaction has already begun? Should it be the DAOs responsibility to obtain the EntityManager 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 EntityManager from the PersistenceUtil class in the Constructor. Is this ok? How about the entityManager field and starting / committing transactions which surrounds DAO calls?

#4 Is it ok that the Servlet initialises a Service 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.

In this exercise, I do not want to use any container 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 concepts correctly, and a good separation of concerns and layering.

I have a database table like this:

and here is my Entity:

This is my PersistenceUtil class:

and in my web application I have a ContextListener:

#2 Is it ok that the DAO Layer requires an EntityManager and assumes that its transaction has already begun? Should it be the DAOs responsibility to obtain the EntityManager 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 EntityManager from the PersistenceUtil class in the Constructor. Is this ok? How about the entityManager field and starting / committing transactions which surrounds DAO calls?

#4 Is it ok that the Servlet initialises a Service object for each call? Or should it have a private static Service object?(I think not, but I am not sure thus asking..)

Source Link
Koray Tugay
  • 1.5k
  • 5
  • 20
  • 44
Loading