Salut à tous,
Je cherche une alternative à un problème d'Hibernate concernant l'utilisation du prédicat isEmpty sur les membres annotés avec ElementCollection (voir https://hibernate.onjira.com/browse/HHH-6686).
voici mon code :
Je cherche donc à remplacer les isEmpty par un équivalent. J'ai tenté avec join et notExists, mais je n'ai pas réussi.
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<Flow> criteriaQuery = criteriaBuilder .createQuery(Flow.class); Root<Flow> root = criteriaQuery.from(Flow.class); criteriaQuery.select(root.alias("flow")); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(criteriaBuilder.equal( root.get("componentTypeReference"), flow.getComponentTypeReference())); predicates.add(criteriaBuilder.equal( root.<ProductionCategory> get("productionCategory"), flow.getProductionCategory())); predicates.add(criteriaBuilder.equal(root.<Device> get("device"), flow.getDevice())); Set<Date> optimalPrintingDates = flow.getOptimalPrintingDates(); if (optimalPrintingDates != null) { Path<Set<Date>> optimalPrintingDatesPath = root .<Set<Date>> get("optimalPrintingDates"); if (optimalPrintingDates.isEmpty()) { predicates.add(criteriaBuilder .isEmpty(optimalPrintingDatesPath)); } else { predicates.add(criteriaBuilder.equal(optimalPrintingDatesPath, flow.getOptimalPrintingDates())); } } Set<Priority> priorities = flow.getPriorities(); if (priorities != null) { Path<Set<Priority>> prioritiesPath = root .<Set<Priority>> get("priorities"); if (priorities.isEmpty()) { predicates.add(criteriaBuilder.isEmpty(prioritiesPath)); } else { predicates.add(criteriaBuilder.equal(prioritiesPath, flow.getPriorities())); } } criteriaQuery.where(predicates.toArray(new Predicate[0])); TypedQuery<Flow> singleFlowQuery = entityManager .createQuery(criteriaQuery); List<Flow> foundFlows = singleFlowQuery.getResultList(); if (foundFlows == null || foundFlows.isEmpty()) { return null; } else if (foundFlows.size() > 1) { throw new NonUniqueResultException("Le flux n'est pas unique : " + foundFlows.size()); } else { return foundFlows.get(0); }
Merci pour toute aide !
Partager