【发布时间】:2017-09-21 14:52:34
【问题描述】:
我开发了一个简单的代码,通过在实体类“Employee”和“Department”上使用 Jpa 的一个 CRUD 操作(查找)来显示员工姓名,它在运行代码时正常工作,但真正的问题出现在我创建时来自应用程序的 jar 文件,jar 文件出现异常,我将异常写在 txt 文件中
这里是 Employee 类
package com.tutorialspoint.eclipselink.entity;
import java.util.*;
import javax.persistence.*;
@Entity
public class Employee {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private int eid;
@Temporal(TemporalType.TIMESTAMP)
private java.util.Date dop;
private String ename;
private double salary;
private String deg;
@OneToOne(targetEntity = Department.class)
private Department dept;
@OneToMany (targetEntity = Staff.class)
private ArrayList<Staff> staffs;
public Employee(int eid, String ename, double salary, String deg) {
super( );
this.eid = eid;
this.ename = ename;
this.salary = salary;
this.deg = deg;
}
public Employee( ) {
super();
}
public Date getDop() {
return dop;
}
public void setDop(Date dop) {
this.dop = dop;
}
public int getEid( ) {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public Department getDept() {
return dept;
}
public void setDept(Department dept) {
this.dept = dept;
}
public String getEname( ) {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public double getSalary( ) {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getDeg( ) {
return deg;
}
public void setDeg(String deg) {
this.deg = deg;
}
public ArrayList<Staff> getStaffs() {
return staffs;
}
public void setStaffs(ArrayList<Staff> staffs) {
this.staffs = staffs;
}
}
这是显示员工姓名和学位的类
public void findEmployee(){
try{
EntityManagerFactory emfactory = Persistence.createEntityManagerFactory( "Eclipselink_JPA" );
EntityManager entitymanager = emfactory.createEntityManager();
Employee employee = entitymanager.find( Employee.class, 204 );
JOptionPane.showMessageDialog(null, employee.getEname()+
"=>"+employee.getDeg());
}catch(Exception ex){
JOptionPane.showMessageDialog(null,ex.getMessage());
displayMsg(ex.getMessage());
}
}
public void displayMsg(String msg){
// i made this method to display the exception in a txt file
File f = new File("E:\\bug2.txt");
FileWriter fw = new FileWriter(f);
PrintWriter pw = new PrintWriter(fw);
pw.println(msg);
pw.flush();pw.close();
}
这是一个例外 " 异常 [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException 异常描述:PersistenceUnit [Eclipselink_JPA] 的部署失败。关闭此 PersistenceUnit 的所有工厂。 内部异常:异常 [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.IntegrityException
描述符异常:
异常 [EclipseLink-1](Eclipse 持久性服务 - 2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.DescriptorException
异常说明:属性 [teacherSet] 未声明为 ValueHolderInterface 类型,但其映射使用间接。
映射:org.eclipse.persistence.mappings.ManyToManyMapping[teacherSet] 描述符:RelationalDescriptor(com.tutorialspoint.eclipselink.entity.Clas --> [DatabaseTable(CLAS)])
异常 [EclipseLink-1] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException 异常说明:属性 [classSet] 未声明为 ValueHolderInterface 类型,但其映射使用间接。 映射:org.eclipse.persistence.mappings.ManyToManyMapping[classSet] 描述符:RelationalDescriptor(com.tutorialspoint.eclipselink.entity.Teacher --> [DatabaseTable(TEACHER)])
异常 [EclipseLink-1](Eclipse 持久性服务 - 2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.DescriptorException
异常描述:属性 [staffs] 未声明为 ValueHolderInterface 类型,但其映射使用间接。 映射:org.eclipse.persistence.mappings.ManyToManyMapping[staffs]
描述符:RelationalDescriptor(com.tutorialspoint.eclipselink.entity.Employee --> [DatabaseTable(EMPLOYEE)])
运行时异常: -------------------------------------------------- ------- "
那么有什么办法呢??知道从 IDE 运行代码时程序运行良好,但是当我构建它并创建 jar 文件并运行 jar 文件时会发生此异常
【问题讨论】:
标签: jpa executable-jar