2014-02-18 65 views
0

我在學習JPAContainer,我無法理解如何配置我的SGBD連接...使用DAO模式創建一個返回我的連接的類。JPAContainer連接?

//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); 
     } 
    } 
} 

如何創建與JPAContainer一起使用的連接?有什麼更好的辦法

回答

0

要開始定義你的jpa持久化單元,可以說「地址簿」。然後您可以使用JPAContainerFactory創建一個新的JPAContainer。

例子:

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

去這樣你就不必處理EntityManager

我強烈建議你跟進this教程,並看看在計算器如下回答:https://stackoverflow.com/a/17876743

+0

但配置我的方面,我需要的EclipseLink的?這些示例http://vaadin.com/download/jpacontainer-tutorial/正在使用EclipseLink,但我不知道如何配置它。我很迷茫:/ – FernandoPaiva

+0

@FernandoPaiva我發現你對JPA沒有多少了解。看看這個教程:http://www.vogella.com/tutorials/JavaPersistenceAPI/article.html – nexus

+0

哇,很好,我會做這個例子。謝謝 – FernandoPaiva