Bonjour,

Je développe une application web en JAVA EE avec jsf primefaces, JPA…
J’essaye de faire un essai très simple car je suis débutant.
J’ai une base de données (MS SQL SERVER) avec 2 tables :
- Formation : IdFormation, NomFormation
- Person : IdPerson, NomPerson, IdFormation

J’ai écrit le code pour les entités comme ceci :
Entité Formation :

Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
@NamedQueries({
	@NamedQuery(name="sqlAllFormation", query="SELECT f FROM Formation f ORDER BY f.idFormation DESC")})
 
@Entity
@Table(name= "Formation")
public class Formation {
 
 
	@Id
	@GeneratedValue( strategy = GenerationType.IDENTITY )
	@Column(name= "IdFormation")
	private long idFormation;
 
	@Column(name="NomFormation")
	@NotNull
	private String nomFormation;
 
	@OneToMany(mappedBy="formation", fetch=FetchType.EAGER)
	private Set<Person> person;
 
	// GETTER SETTER
 
}
Entité Person :
Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
@Entity
@Table(name="Person")
public class Person implements Serializable {
 
 
	private static final long serialVersionUID = 1L;
 
 
	@Id
	@GeneratedValue( strategy = GenerationType.IDENTITY )
	@Column(name= "IdPerson")
	private long idPerson;
 
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="IdFormation")
	private Formation formation;
 
	@Column(name="NomPerson")
	private String nomPerson;
 
	//GETTER SETTER
FormationDao :
Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
@Stateless
public class FormationDao {
 
	@PersistenceContext( unitName = "bdd" )
	private EntityManager em;
 
	public List<Formation> liste_formation () throws DAOException {
 
		try {
			TypedQuery<Formation> sql = em.createNamedQuery("sqlAllFormation", Formation.class);
			return sql.getResultList();
		} catch ( DAOException e ) {
			throw new DAOException( e );
		}
	}
 
}

Backing Bean ListeFormation :




Code JAVA : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
@ManagedBean
@ViewScoped
public class ListeFormation implements Serializable {
 
	private static final long serialVersionUID = 1L;
 
	/*Liste */
	private List<Formation> listeFormation = new ArrayList<Formation>();
 
	// Injection des EJB (Session Bean Stateless)
	@EJB
	private FormationDao formationDao;
 
	public List<Formation> getListeFormation() {
		listeFormation = formationDao.liste_formation();
		return listeFormation;
	}
 
}

La page liste_formation.xhtml
Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:b="http://bootsfaces.net/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
 
<h:head>
	  <meta charset="utf-8"></meta>
		<h:outputStylesheet library="default" name="style.css" />
</h:head>
 
<h:body>
<ui:include src="/resources/entete/entete.xhtml"/>
 
<b:container>
<div>
	<h1 class="black">Liste des formations</h1></div>
		<br />
		<br />
<h:form>
 
	<p:dataTable id="dataTable" var="ls_f" value="#{listeFormation.listeFormation}" paginator="true" rows="10" paginatorPosition="bottom" emptyMessage="Aucun résultat trouvé." scrollable="true" scrollWidth="auto">
        <f:facet name="header">
			Liste des Formation
		</f:facet>
 
		<p:column id="idF" headerText="N°Formation"
			filterBy="#{ls_f.idFormation}" filterMatchMode="contains">
            	<h:outputText id="idCell" value="#{ls_f.idFormation}"/>
            </p:column>
            <p:column id="nomFormation" headerText="Formation"
            	filterBy="#{ls_f.nomFormation}" filterMatchMode="contains">
            	<h:outputText id="idCell1" value="#{ls_f.nomFormation}"/>
            </p:column>
			<p:column id="persons" headerText="Persons">
            	<h:dataTable value="#{ls_f.person}" var="p" styleClass="innerTab">
 
						<h:column>#{p.idPerson} - #{p.nomPerson}</h:column>
    			</h:dataTable>
            </p:column>
 
          	</p:dataTable>
 
</h:form>	
 
	</b:container>
 
</h:body>
</html>

La question:
Quand je modifie ou j’ajoute une personne à une formation via Microsoft SQL Management Studio le changement n’apparait pas immédiatement sur ma page. Je suis obligé de redémarrer mon serveur GLASSFISH.
Dès fois la formation s’affiche toute suite sur mon tableau mais pas les personnes liées même si j’utilise fetch=FetchType.EAGER dans mes entités.

Est-ce que JPA Stock les données et n’émet pas de requête à chaque fois même si la console m’affiche la requête ?

Merci d’avance.