Salut.

Je genere une requete EBJQL dynamiquement pour les conditions mais c'est un peu lourd.

Il n'existe pas une autre facon plus classe?

Un exemple:

Code : 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
 
	public List<Project> getDataGridProject() {
		String SQLCondition = "";
		if (selectedInstitution != null)
			SQLCondition = " WHERE institution=:institution";
 
		if (selectedArs != null)
			if (SQLCondition.equals(""))
				SQLCondition = " WHERE institution.ars=:ars";
			else
				SQLCondition += " AND institution.ars=:ars";
 
		if (selectedPlan != null)
			if (SQLCondition.equals(""))
				SQLCondition = " WHERE plan=:plan";
			else
				SQLCondition += " AND plan=:plan";
 
		List<Project> listProject = new ArrayList<Project>();
		String sql = "SELECT p FROM Project p" + SQLCondition;
		System.out.println("sql: " + sql);
		Query q = entityManager.createQuery(sql);
 
		if (selectedInstitution != null)
			q.setParameter("institution", selectedInstitution);
		if (selectedPlan != null)
			q.setParameter("plan", selectedPlan);
		if (selectedArs != null)
			q.setParameter("ars", selectedArs);
 
		listProject = q.getResultList();
		return listProject;
	}
merci