手動であなたにIDを割り当てられたので、それが教育org.hibernate.PersistentObjectException:永続化するために渡されたデタッチエンティティ:com.hibernate.dto.Employee
@Entity
public class Employee {
@Id
@GeneratedValue
private int empId;
private String empName;
@Temporal(TemporalType.DATE)
private Date empDob;
@Temporal(TemporalType.TIMESTAMP)
private Date empDoj;
private Long empPhone;
@OneToMany(cascade=CascadeType.PERSIST)
//setter and getters
}
@Entity
public class Education {
@Id
@GeneratedValue
private Integer aadharNum;
private String collegeName;
private String schoolName;
private String companyName;
// setter and getter
}
public class HibernateTest {
public static void main(String[] args) {
try {
Employee employee=new Employee();
employee.setEmpName("Sri");
employee.setEmpId(7664);
employee.setEmpDob(new java.util.Date());
employee.setEmpDoj(new java.util.Date());
employee.setEmpPhone(8102087655l);
Education education=new Education();
education.setSchoolName("Neo Royal School");
education.setCollegeName("IIT Gu");
education.setCompanyName("Insys");
Education education2=new Education();
education2.setSchoolName("Royal School");
education2.setCollegeName("IIT Hyd");
education2.setCompanyName("IM");
employee.getEducation().add(education);
employee.getEducation().add(education2);
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session session=sessionFactory.openSession();
session.beginTransaction();
session.persist(employee);
session.getTransaction().commit();
session.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
訂正していただきありがとうございます。 – Srinu
@johnは修正のためにハンクスを働かせました。 – Srinu
彼の答えを受け入れてください –