String numeGrupaTest = "GrupaTest";
String numeGrupaTest1 = "GrupaTest1";
String prenumeTest = "prenumeStudentTest";
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
Grupa g = new Grupa();
g.setNumeGrupa(numeGrupaTest);
em.persist(g);
int idGr = g.getIdGrupa();
Student studentTest = new Student();
studentTest.setIdGrupa(idGr);
studentTest.setAnStudiu(anStudiuTest);
studentTest.setEmail(emailTest);
studentTest.setNrMatricol(numarMatricolTest);
studentTest.setNume(numeTest);
studentTest.setPrenume(prenumeTest);
g.getStudenti().add(studentTest);
em.persist(g);
Query q = em.createNativeQuery("SELECT student.studenti_id_grupa FROM Student WHERE student.studenti_id_grupa=?1")
.setParameter(1, idGr);
List st = q.getResultList();
q = em.createQuery("select s from Student s");
Student s = new Student();
s = (Student) q.getSingleResult();
assertEquals(st.size(), 1);
Grupa g1 = new Grupa();
g1.setNumeGrupa(numeGrupaTest1);
em.persist(g1);
int idGr1 = g1.getIdGrupa();
g1.getStudenti().add(s);
em.persist(g1);
q = em.createNativeQuery(
"SELECT student.studenti_id_grupa FROM Student WHERE student.studenti_id_grupa=?1")
.setParameter(1, idGr1);
List st1 = q.getResultList();