public static void updateStudent(StudentForm studentUpdate,
String nrMatricol) {
Student toBeUpdatedStudent = new Student();
Grupa g = new Grupa();
EntityManagerFactory emf = Persistence
.createEntityManagerFactory("modul3L2");
em = emf.createEntityManager();
em.getTransaction().begin();
Query query = em.createQuery(
"SELECT s FROM Student s WHERE s.nrMatricol=:v1").setParameter(
"v1", nrMatricol);
toBeUpdatedStudent = (Student) query.getSingleResult();
String numeGrupa = (String) em
.createNativeQuery(
"SELECT grupa.NUME_GRUPA FROM Grupa,Student WHERE grupa.ID_GRUPA=student.studenti_id_grupa AND student.NR_MATRICOL=?1")
.setParameter(1, nrMatricol).getSingleResult();
g = (Grupa) em
.createQuery("SELECT g FROM Grupa g WHERE g.numeGrupa=:v1")
.setParameter("v1", numeGrupa).getSingleResult();
g.getStudenti().remove(g.getStudenti().indexOf(toBeUpdatedStudent));
em.merge(g);
toBeUpdatedStudent.setAnStudiu(Integer.valueOf(studentUpdate.getAn())
.intValue());
toBeUpdatedStudent.setNrMatricol(studentUpdate.getNrMatricol());
toBeUpdatedStudent.setNume(studentUpdate.getNumeBaza());
toBeUpdatedStudent.setPrenume(studentUpdate.getPrenume());
toBeUpdatedStudent.setEmail(studentUpdate.getEmail());
if (studentUpdate.getGrupa().equals(numeGrupa)) {
g = (Grupa) em
.createQuery("SELECT g FROM Grupa g WHERE g.numeGrupa=:v1")
.setParameter("v1", numeGrupa).getSingleResult();