標籤: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&characterEncoding=UTF-8"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit></persistence>
比較:
1、先建表後根據表來編寫設定檔和實體bean。這是傳統的資料庫建模方案。
2、先編寫設定檔和實體類bean,然後再產生表。這是領域建模思想方案,這種思想相對於前一種更加的 OOP。
JPA學習---第二節:JPA開發環境和思想介紹