1. 根据openjpa 版本,获取正确的GBase 字典包。
2. 引入openjpa 包, gbase 数据库字典包和jdbc 驱动。
3. 设置persistence.xml 文件,参考黑色背景设置。
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
org.apache.openjpa.persistence.PersistenceProviderImpl
value="
org.apache.openjpa.jdbc.sql.GBaseDictionary "/>
value="com.gbase.jdbc.Driver" />
value="jdbc:gbase://192.168.7.235:5258/openjpatest" />
GBase UP 产品手册 6 应用开发指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 1069
3.
程序验证
package com.test;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.demo1.Bjcy;
public class TestJpa {
private static EntityManagerFactory emf;
private static ThreadLocal
public static void main(String[] args) {
emf = Persistence.createEntityManagerFactory("JPAJC1");
threadLocal = new ThreadLocal
Bjcy entity = new Bjcy();
getEntityManager().persist(entity);
}
public static EntityManager getEntityManager() {
EntityManager manager = threadLocal.get();
if (manager == null || !manager.isOpen()) {
manager = emf.createEntityManager();
threadLocal.set(manager);
}
return manager;
}
}