[JIRA] (HHH-17012) Using CriteriaBuilder not method mutates original predicate in SQL
by Ilya Ryzhov (JIRA)
Ilya Ryzhov ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f65f49... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmVmOTk5NjAw... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiNmVmOT... ) HHH-17012 ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiNmVmOT... ) Using CriteriaBuilder not method mutates original predicate in SQL ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiNmVmOT... )
Change By: Ilya Ryzhov ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f65f49... )
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.
( https://hibernate.atlassian.net/browse/HHH-17012#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-17012#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:da16c62 )
2 years, 3 months
[JIRA] (HHH-17012) Using CriteriaBuilder not method mutates original predicate in SQL
by Илья Рыжов (JIRA)
Илья Рыжов ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f65f49... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZjI5ZjRkNGVm... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiZjI5Zj... ) HHH-17012 ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiZjI5Zj... ) Using CriteriaBuilder not method mutates original predicate in SQL ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiZjI5Zj... )
Change By: Илья Рыжов ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f65f49... )
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:
{ noformat 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
){ noformat code }
Maybe I missed something in release notes and migration guides, but it looks like a unintended behavior.
( https://hibernate.atlassian.net/browse/HHH-17012#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-17012#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:da16c62 )
2 years, 3 months
[JIRA] (HHH-17012) Using CriteriaBuilder not method mutates original predicate in SQL
by Илья Рыжов (JIRA)
Илья Рыжов ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f65f49... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNGQ4YWJhZWQ4... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiNGQ4YW... ) HHH-17012 ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiNGQ4YW... ) Using CriteriaBuilder not method mutates original predicate in SQL ( https://hibernate.atlassian.net/browse/HHH-17012?atlOrigin=eyJpIjoiNGQ4YW... )
Issue Type: Bug Assignee: Unassigned Created: 31/Jul/2023 00:49 AM Environment: hibernate-core - 6.2.5.Final
jvm 17
db - postgres 12.5 Priority: Major Reporter: Илья Рыжов ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f65f49... )
Using CriteriaBuilder’s not() with predicate or Predicate’s not() generates negated original SQL-predicate.
Entity class:
@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,
)
Specification producing wrong SQL:
someEntityRepository.findAll { root, _, cb ->
val predicate = cb.isNull(root[SomeEntity_.name])
val negation = cb.not(predicate)//same with predicate.not()
cb.and(predicate, negation)
}
SQL generated in 6.2.5.Final:
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
SQL generated in 5.6.15.Final:
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
)
Maybe I missed something in release notes and migration guides, but it looks like a unintended behavior.
( https://hibernate.atlassian.net/browse/HHH-17012#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-17012#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100233- sha1:da16c62 )
2 years, 3 months