JPA學習---第二節:JPA開發環境和思想介紹

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   os   java   sp   

一、下載相關 jar

http://hibernate.org/orm/ 下載 hibernate ,解壓

http://www.slf4j.org/download.html 下載 slf4j,解壓

http://www.apache.org/dyn/closer.cgi/logging/log4j/2.0.2/apache-log4j-2.0.2-bin.zip 下載 log4j, 解壓

二、開發 JPA 依賴的jar

hibernate-release-4.3.6.Final\lib\required\*.jar

hibernate-release-4.3.6.Final\lib\jpa\hibernate-entitymanager-4.3.6.Final.jar

hibernate-release-4.3.6.Final\lib\optional\ehcache\slf4j-api-1.6.1.jar

三、 JPA 設定檔

JPA規範要求在類路徑的META-INF目錄下放置persistence.xml,檔案的名稱是固定的,配置模版如下:

<?xml version="1.0"?><persistence xmlns="http://java.sun.com/xml/ns/persistence"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence                 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"     version="1.0">  <persistence-unit name="itcast" transaction-type="RESOURCE_LOCAL">      <properties>         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>         <property name="hibernate.connection.driver_class" value="org.gjt.mm.mysql.Driver"/>         <property name="hibernate.connection.username" value="root"/>         <property name="hibernate.connection.password" value="123456"/>         <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/itcast?useUnicode=true&amp;characterEncoding=UTF-8"/>         <property name="hibernate.hbm2ddl.auto" value="update"/>      </properties>  </persistence-unit></persistence>

比較:

1、先建表後根據表來編寫設定檔和實體bean。這是傳統的資料庫建模方案。

2、先編寫設定檔和實體類bean,然後再產生表。這是領域建模思想方案,這種思想相對於前一種更加的 OOP。

JPA學習---第二節:JPA開發環境和思想介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.