Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have employee certifications I want to make sure they have been checked by a p

ID: 3556102 • Letter: I

Question

I have employee certifications I want to make sure they have been checked by a person, How do i do that in java. I have tried this.

private void copyEmployeeCertPub(Company comp, EntityManager em) {
List<EmployeeCertification> empls
= em.createNamedQuery("EmployeeCertification.findByCompId", EmployeeCertification.class)
.setParameter("compId", comp.getCompId())
.getResultList();
for (EmployeeCertification empl : empls) {

EmployeeCertPub employeeCertPub = em.find(EmployeeCertPub.class, comp);

employeeCertPub.setExpDate(empl.getExpDate());
employeeCertPub.setDocPath(empl.getDocPath());
employeeCertPub.setEmployee(empl.getEmployee());
employeeCertPub.setCertification(empl.getCertification());

util.merge(employeeCertPub, em);

Explanation / Answer

1. Since you are doing an update operation here, you need to begin a transaction before the fetch operation and then commit when all is done.

2. The EntityManager.find() method fetches the object based on primary key and you must check if Company class is your primary key.

3. I don't know 'uitl' is object of which class, so you have to check that. I think em.merge() will do just fine.

I can help better If you can give the whole entity class and the named query too. Please let me know if you have any doubt.

private void copyEmployeeCertPub(Company comp, EntityManager em) {
      
       em.getTransaction().begin();
      
       List<EmployeeCertification> empls
       = em.createNamedQuery("EmployeeCertification.findByCompId", EmployeeCertification.class)
       .setParameter("compId", comp.getCompId())
       .getResultList();
       for (EmployeeCertification empl : empls) {
       EmployeeCertPub employeeCertPub = em.find(EmployeeCertPub.class, comp);
       employeeCertPub.setExpDate(empl.getExpDate());
       employeeCertPub.setDocPath(empl.getDocPath());
       employeeCertPub.setEmployee(empl.getEmployee());
       employeeCertPub.setCertification(empl.getCertification());
       util.merge(employeeCertPub, em);
      
       em.getTransaction().commit();
      
       }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote