0

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 ?

FernandoPaiva
  • 4,410
  • 13
  • 59
  • 118

1 Answers1

0

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

Community
  • 1
  • 1
nexus
  • 2,937
  • 3
  • 17
  • 22
  • but to configure my connection I need of eclipselink ? These examples http://vaadin.com/download/jpacontainer-tutorial/ are using EclipseLink, but I don't know how to configure that. I'm so lost :/ – FernandoPaiva Feb 18 '14 at 18:45
  • @FernandoPaiva Well I see that you don't have much knowledge about JPA. Have a look at this tutorial: http://www.vogella.com/tutorials/JavaPersistenceAPI/article.html – nexus Feb 18 '14 at 19:02