前面章节介绍了 JPA 和 OpenJPA 基础知识,本章节将为后续学习 OpenJPA 做准备工作。
(1)OpenJPA Maven 依赖 ,如下:
<dependency> <groupId>org.apache.openjpa</groupId> <artifactId>openjpa-all</artifactId> <version>2.4.2</version> </dependency>
(2)OpenJPA 的其他 Maven 依赖,如下:
<dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-asm5-shaded</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>net.sourceforge.serp</groupId> <artifactId>serp</artifactId> <version>1.15.1</version> </dependency> <dependency> <groupId>org.apache.bval</groupId> <artifactId>org.apache.bval.bundle</artifactId> <version>0.5</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jta_1.1_spec</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jpa_2.0_spec</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-jms_1.1_spec</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>10.12.1.1</version> <scope>test</scope> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.2</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.2</version> </dependency>
(3)MySQL 数据库驱动 Maven 依赖,如下:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.46</version> </dependency>
(1)先在 MySQL 创建名为“openjpa_learn”的数据库,如下图:
数据库SQL语句如下:
create database if not exists openjpa_learn default character set utf8 collate utf8_general_ci;
(2)下载下面 SQL 脚本,然后在 openjpa_learn 中执行该SQL 脚本。
执行成功后数据库表如下图: