1. download relevant jar files
Http://hibernate.org/orm/ download hibernate, unzip
Http://www.slf4j.org/download.html download slf4j, unzip
Http://www.apache.org/dyn/closer.cgi/logging/log4j/2.0.2/apache-log4j-2.0.2-bin.zip download log4j, unzip
2. Develop the jar on which JPA depends
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
Iii. JPA configuration file
The JPA specification requires persistence. XML to be placed under the META-INF directory of the class path, the file name is fixed, and the configuration template is as follows:
<?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>
Comparison:
1. Create a table and write the configuration file and Entity Bean Based on the table. This is a traditional database modeling solution.
2. First write the configuration file and entity-class bean, and then regenerate the table. This is the idea of Domain Modeling. This idea is more OOP than the previous one.
JPA learning-Section 2: Introduction to the JPA development environment and ideas