Using CriteriaBuilder’s not() with predicate or Predicate’s not() generates negated original SQL-predicate. Entity class:
{noformat}@Entity @Table(name = "some_table") class SomeEntity( @Id @GeneratedValue(generator = "some_id_seq") @SequenceGenerator(name = "some_id_seq", sequenceName = "some_id_seq", allocationSize = 1) @Column(name = "id") val id: Int? = null,
@Column(name = "name") var name: String? = null, ){noformat}
Specification producing wrong SQL:
{noformat}someEntityRepository.findAll { root, _, cb -> val predicate = cb.isNull(root[SomeEntity_.name]) val negation = cb.not(predicate)//same with predicate.not() cb.and(predicate, negation) }{noformat}
SQL generated in 6.2.5.Final:
{code:sql}select s1_0.id, s1_0.name from some_table s1_0 where s1_0.name is not null and s1_0.name is not null{code}
SQL generated in 5.6.15.Final:
{code:sql}select someentity0_.id as id1_56_, someentity0_.name as name2_56_ from distributor_test. some_table someentity0_ where ( someentity0_.name is null ) and ( someentity0_.name is not null ){code}
Maybe I missed something in release notes and migration guides, but it looks like a unintended behavior. |
|