zoukankan      html  css  js  c++  java
  • JPA学习---第二节:JPA开发环境和思想介绍

    一、下载相关 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.Finallib equired*.jar

    hibernate-release-4.3.6.Finallibjpahibernate-entitymanager-4.3.6.Final.jar

    hibernate-release-4.3.6.Finalliboptionalehcacheslf4j-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。

  • 相关阅读:
    Vim配置及使用技巧
    终端提示符的配置
    Archlinux下i3wm与urxvt的配置
    Linux压缩命令
    Archlinux无线联网教程
    Archlinux安装和使用技巧
    Linux下硬盘分区
    Linux挂载
    Android中pullToRefresh使用
    SVN服务器搭建和使用教程
  • 原文地址:https://www.cnblogs.com/hwlsniper/p/4077220.html
Copyright © 2011-2022 走看看