Вопрос

I'm learning JPAContainer, and I can't understand how to configure my SGBD connection...Using DAO mode I create an class that return my connection.

//ConnectionFactory DAO mode
public class ConnectionFactory {
    public Connection getConnection() {
        try {
            return DriverManager.getConnection(
              "jdbc:mysql://localhost/fj21", "root", "");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

How to create connection for to use with JPAContainer ? What better way ?

Это было полезно?

Решение

To start define your jpa persistence unit, lets say "addressbook". Then you could create a new JPAContainer using the JPAContainerFactory.

Example:

JPAContainerFactory.make(Person.class, JpaAddressbookApplication.PERSISTENCE_UNIT); // where PERSISTENCE_UNIT = "addressbook"

Going this way you don't have to deal with the EntityManager.

I highly recommend you to follow up this tutorial and have a look at the following answer on stackoverflow: https://stackoverflow.com/a/17876743

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top