<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 概述 全稱Java Persistence Api,java的持久化規范. JPA是一套接口,hibernate是實現.所有的ORM框架都可以實現JPA接口.hibernate有自己的獨立的ORM操作方式.也有JPA規范實現的操作方式. ## JAP的使用 JPA是通過注解的方式來描述對象和表的映射關系.之前的對象和表的映射關系是通過XML. ## 配置 持久化類配置: ~~~ //標注此類為持久化類 @Entity //標注表名 @Table(name = "customer") public class Customer { //標注為主鍵,OID @Id //和表的哪個字段做映射 @Column(name = "cust_id") //增長策略,OID的增長策略 @GeneratedValue(strategy = GenerationType.AUTO) private Long cust_id; //其他屬性和表中字段映射,如果一樣可以不寫 @Column(name = "cust_name") private String cust_name; private String cust_industry; private String cust_source; private String cust_level; private String cust_phone; private String cust_address; } ~~~ 在src下有一個META-INF文件夾,在MRTA-INF文件下下有一個persistence.xml文件.所有的數據庫信息配置都在這個文件中來配置. persistence.xml 文件配置: ~~~ <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <!--至少要有一個持久化單元(至少有一個數據庫的連接信息)--> <!--名字可以隨便取--> <persistence-unit name="mysql"> <properties> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.url" value="jdbc:mysql://192.168.10.10:3306/hibernate?useSSL=false&amp;characterEncoding=utf-8"/> <property name="hibernate.connection.username" value="homestead"/> <property name="hibernate.connection.password" value="secret"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.connection.provider_class" value="org.hibernate.c3p0.internal.C3P0ConnectionProvider"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.current_session_context_class" value="thread"/> </properties> </persistence-unit> <persistence-unit name="oracle"> <!--oracle配置--> </persistence-unit> <persistence-unit name="db2"> <!--db2配置--> </persistence-unit> </persistence> ~~~ 測試: ~~~ //加載數據庫信息.xml文件中填寫的名稱. 以下這步相當于sessionFactory EntityManagerFactory factory = Persistence.createEntityManagerFactory("mysql"); //獲取連接session EntityManager entityManager = factory.createEntityManager(); //獲取事務 EntityTransaction tx = entityManager.getTransaction(); //開啟事務 tx.begin(); Customer customer = new Customer(); customer.setCust_name("jack"); //相當于save() entityManager.persist(customer); tx.commit(); entityManager.close(); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看