2525/**
2626 * @author Jan Schatteman
2727 */
28- @ Jpa (
29- annotatedClasses = {Wall .class },
30- jpaComplianceEnabled = false
31- )
3228@ JiraKey ( value = "HHH-17493" )
3329public class NegatedPredicateTest {
3430
@@ -56,6 +52,10 @@ public void tearDown(EntityManagerFactoryScope scope) {
5652 );
5753 }
5854
55+ @ Jpa (
56+ annotatedClasses = {Wall .class },
57+ jpaComplianceEnabled = false
58+ )
5959 @ Test
6060 public void testNegatedPredicate (EntityManagerFactoryScope scope ) {
6161 scope .inEntityManager (
@@ -78,6 +78,10 @@ public void testNegatedPredicate(EntityManagerFactoryScope scope) {
7878 );
7979 }
8080
81+ @ Jpa (
82+ annotatedClasses = {Wall .class },
83+ jpaComplianceEnabled = false
84+ )
8185 @ Test
8286 public void testDoubleNegatedPredicate (EntityManagerFactoryScope scope ) {
8387 scope .inEntityManager (
@@ -103,4 +107,61 @@ public void testDoubleNegatedPredicate(EntityManagerFactoryScope scope) {
103107 }
104108 );
105109 }
110+
111+ @ Jpa (
112+ annotatedClasses = {Wall .class },
113+ jpaComplianceEnabled = true
114+ )
115+ @ Test
116+ public void testJpaCompliantNegatedPredicate (EntityManagerFactoryScope scope ) {
117+ scope .inEntityManager (
118+ entityManager -> {
119+ CriteriaBuilder cb = entityManager .getCriteriaBuilder ();
120+ CriteriaQuery <Wall > query = cb .createQuery ( Wall .class );
121+ Root <Wall > root = query .from ( Wall .class );
122+ query .select ( root ).where (
123+ cb .not (
124+ cb .or (
125+ cb .equal (root .get ( "color" ), "yellow" ),
126+ cb .equal (root .get ( "color" ), "red" )
127+ )
128+ )
129+ );
130+ Wall result = entityManager .createQuery ( query ).getSingleResult ();
131+ assertNotNull ( result );
132+ assertEquals ("green" , result .getColor ());
133+ }
134+ );
135+ }
136+
137+ @ Jpa (
138+ annotatedClasses = {Wall .class },
139+ jpaComplianceEnabled = true
140+ )
141+ @ Test
142+ public void testJpaCompliantDoubleNegatedPredicate (EntityManagerFactoryScope scope ) {
143+ scope .inEntityManager (
144+ entityManager -> {
145+ CriteriaBuilder cb = entityManager .getCriteriaBuilder ();
146+ CriteriaQuery <Wall > query = cb .createQuery ( Wall .class );
147+ Root <Wall > root = query .from ( Wall .class );
148+ query .select ( root ).where (
149+ cb .not (
150+ cb .not (
151+ cb .or (
152+ cb .equal (root .get ( "color" ), "yellow" ),
153+ cb .equal (root .get ( "color" ), "red" )
154+ )
155+ )
156+ )
157+ );
158+ query .orderBy ( cb .asc (root .get ("id" )) );
159+ List <Wall > result = entityManager .createQuery ( query ).getResultList ();
160+ assertEquals ( 2 , result .size () );
161+ assertEquals ("yellow" , result .get (0 ).getColor ());
162+ assertEquals ("red" , result .get (1 ).getColor ());
163+ }
164+ );
165+ }
166+
106167}
0 commit comments