私はeclipselinkまたはjpaを初めて利用しています。私はhereからeclipselinkのチュートリアルに従っていました。 Test.javaクラスを実行すると、次の例外が発生します。私はネットワーク上でOracleデータベースを使用しています。私を助けてください。オブジェクト:既知のエンティティタイプではありません。 Eclipselink
[EL Info]: connection: 2016-09-14 15:13:33.562--ServerSession(271944754)--/file:/D:/Developer/EclipseLink/bin/_TestPersistence login successful
[EL Warning]: metamodel: 2016-09-14 15:13:33.577--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
Exception in thread "main" java.lang.IllegalArgumentException: Object: Employee [name=Mukesh, [email protected] , department=Finance] is not a known Entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4226)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:507)
at com.assignment.Test.main(Test.java:28)
persistence.xmlの
<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="TestPersistence"
transaction-type="RESOURCE_LOCAL">
<class>com.assignment.Employee</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:oracle:thin:@ipaddress:port/servicename" />
<property name="javax.persistence.jdbc.user" value="username" />
<property name="javax.persistence.jdbc.password"
value="password" />
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
</persistence>
Employee.java
package com.assignment;
public class Employee {
private Long id;
private String name;
private String email;
private String department;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String toString() {
return "Employee [name=" + name + ", email=" + email + " , department="
+ department + "]";
}
}
Test.java
package com.assignment;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
public class Test {
private static final String PERSISTENCE_UNIT_NAME = "TestPersistence";
private static EntityManagerFactory factory;
public static void main(String[] args) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
Employee emp = new Employee();
emp.setName("Mukesh");
emp.setEmail("[email protected]");
emp.setDepartment("Finance");
em.persist(emp);
em.getTransaction().commit();
em.close();
}
}
パッケージ構造
これは、サイトが探している回答ではありません。これは最高で貧弱なコメントであり、基本的にはリンクのみの回答です死ぬ –