Add Session.html and lombok, change property access into field access to lombok.
Tested add Session to user, add method UtilisateurDAO.addToSession Please rerun mvn clean install
This commit is contained in:
@@ -2,8 +2,11 @@ package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
||||
public UtilisateurDAO() {
|
||||
super();
|
||||
@@ -29,4 +32,25 @@ public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
||||
t.commit();
|
||||
return u;
|
||||
}
|
||||
|
||||
public void addToSession(int sessionId, int userId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Session s = em.find(Session.class, sessionId);
|
||||
Utilisateur u = em.find(Utilisateur.class, userId);
|
||||
|
||||
//ERROR NULLPOINTEREXCEPTION
|
||||
if (u.getSession() == null) {
|
||||
u.setSession(new ArrayList<>());
|
||||
}
|
||||
if (s.getUtilisateurs() == null) {
|
||||
s.setUtilisateurs(new ArrayList<>());
|
||||
}
|
||||
|
||||
//FAUT AJOUTER OWNING SIDE ( Ici u --> s)
|
||||
u.getSession().add(s);
|
||||
s.getUtilisateurs().add(u);
|
||||
em.merge(u);
|
||||
t.commit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user