Eclipse + Mysql + OpenJpa 开发环境搭建

1、要下载OpenJPA的具体实现,一共8个jar文件,一个都不能少,全部都要导入到Eclipse中

2、下载 mysql-connector-java-5.1.7 ,导入到Eclipse中。

3、实体的ID生成策略一定要设置为 IDENTITY

4、数据库表中的ID字段,一定要设置为 AUTO_INCREMENT

 

配置文件:

<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" 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"> <persistence-unit name="JPA_Test" transaction-type="RESOURCE_LOCAL"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <class>andycpp.Customer</class> <class>andycpp.Address</class> <class>andycpp.OnlineCustomer</class> <class>andycpp.Invoice</class> <class>andycpp.Order</class> <properties> <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/jpa_test"/> <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/> <property name="openjpa.ConnectionUserName" value="root"/> <property name="openjpa.ConnectionPassword" value="123456"/> <property name="openjpa.Log" value="SQL=TRACE"/> </properties> </persistence-unit> </persistence>

你可能感兴趣的:(eclipse,mysql,数据库,jdbc,jpa,encoding)