P
P
parkito2016-08-30 03:16:59
Java
parkito, 2016-08-30 03:16:59

How to properly organize the application architecture?

Hello. Can you please suggest how best to design the application architecture.
I am writing a web application that will add to the database and read from it the information of users, as well as about their products.

I described all the entities

public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "user_id")
    private int userId;
    @Basic
    @Column(name = "name")
    private String name;
...


Made a DAO layer

public class UserDAO extends {
    public User getUserByNumber(String number) throws UserNotFoundException;
    public User getUserByEMAil(String eMail) throws UserNotFoundException;
...


Services layer.

public class UserService {
    private UserDAO userDAO = new UserDAO();

  
    public void createEntity(User user) throws CustomDAOException {
        if (!isUserExists(user))
            userDAO.create(user);
        else System.out.println("User already exists");
    }
...


Now I don't know what to do with the creation of EntityManagerFactory and EntityManager Where is the best place to place them? How can I make them close on successful completion of the program (where is the best place to close them?) in multi-threaded mode?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Kozak, 2016-09-01
@parkito

I can offer the following hierarchy (package structure) in a simple version, it might look like this:
com.example.application:
it has the following layers:
accordingly, in resourse we take out the entire configuration (application contexts, configurations, properties) and also preferably everything by folders (frameworks that are used, for example, spring, hibernate, or the Java EE specification that decouples us, well, or tries to do this, from specific providers): )
I also advise you to google SOA / microservices
And also a useful article Learning to design based on the subject area ...

E
Eugene, 2016-08-30
@zolt85

Just describe them in the configuration, Hibernate will do the rest for you. Just read the documentation before you fence the garden.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question