I've developed a simple code that displayes employee name by using Jpa's one of CRUD operations(find) on entity classes "Employee"& "Department" it worked properly while running the code , but the real problem came when I created a jar file from the application, an exception appeared from the jar file , I wrote the exception in a txt file
Here is the Employee class
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;
}
}
and here is the class that displays employee name and degree
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();
}
and here is the exception " Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Deployment of PersistenceUnit [Eclipselink_JPA] failed. Close all factories for this PersistenceUnit. Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
Exception [EclipseLink-1] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [teacherSet] is not declared as type ValueHolderInterface, but its mapping uses indirection.
Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[teacherSet] Descriptor: RelationalDescriptor(com.tutorialspoint.eclipselink.entity.Clas --> [DatabaseTable(CLAS)])
Exception [EclipseLink-1] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The attribute [clasSet] is not declared as type ValueHolderInterface, but its mapping uses indirection. Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[clasSet] Descriptor: RelationalDescriptor(com.tutorialspoint.eclipselink.entity.Teacher --> [DatabaseTable(TEACHER)])
Exception [EclipseLink-1] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The attribute [staffs] is not declared as type ValueHolderInterface, but its mapping uses indirection. Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[staffs]
Descriptor: RelationalDescriptor(com.tutorialspoint.eclipselink.entity.Employee --> [DatabaseTable(EMPLOYEE)])
Runtime Exceptions: --------------------------------------------------------- "
so what can be done?? knowing that the program works well when running the code from IDE but this exception happens when i built it and created jar file and ran the jar file