简体   繁体   English

JPAContainer连接?

[英]JPAContainer connection?

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. 我正在学习JPAContainer,但我不明白如何配置SGBD连接...使用DAO模式,我创建了一个返回连接的类。

//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 ? 如何创建用于JPAContainer的连接? What better way ? 有什么更好的办法?

To start define your jpa persistence unit, lets say "addressbook". 要开始定义jpa持久性单元,请说“地址簿”。 Then you could create a new JPAContainer using the JPAContainerFactory . 然后,您可以使用JPAContainerFactory创建一个新的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 . 通过这种方式,您不必处理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 我强烈建议您继续学习教程,并在stackoverflow上查看以下答案: https : //stackoverflow.com/a/17876743

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM