我正在尝试使用 JPA 和 EclipseLink 保留元素。所以我创建了一个类来坚持
@Entity
public class Couple implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name = "OBJECTID")
private String objectID;
@Column(name = "EPCNUMBER")
private String epcNumber;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
等等。我创建了一个类来“使用”它:
public class Main {
private static final String PERSISTENCE_UNIT_NAME = "MyPU";
private static EntityManagerFactory factory;
public static void main(String[] args) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
TypedQuery<Couple> q = em.createQuery("SELECT c FROM Couple c", Couple.class);
List<Couple> couples = (List<Couple>) q.getResultList();
然后,我有以下 persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="MyPU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>localJTA</jta-data-source>
<class>fr.mypackage.com.Couple</class>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>
但是,即使我更改了属性,我也遇到了同样的错误:
线程“主”javax.persistence.PersistenceException 中的异常:没有名为 MyPU 的 EntityManager 的持久性提供程序(调用 factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME); 时)。
我对 ling xml 和持久性单元做错了吗?我已经在类路径中添加了以下内容:
javax.persistence.jar
javax.ejb.jar
eclipselink.jar
javax.persistence_1.0.0.jar
javax.persistence_2.0.4.v201112161009.jar
derby.jar
你可以帮帮我吗 ?谢谢 !