Aivis Heniņš (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNzI0NmY2Y2Vm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16878?atlOrigin=eyJpIjoiNzI0Nm...
) HHH-16878 (
https://hibernate.atlassian.net/browse/HHH-16878?atlOrigin=eyJpIjoiNzI0Nm...
) Invalid SQL generated for mutation when using association with @NotFound (
https://hibernate.atlassian.net/browse/HHH-16878?atlOrigin=eyJpIjoiNzI0Nm...
)
Issue Type: Bug Affects Versions: 6.2.6 Assignee: Unassigned Attachments:
ORMUnitTestCase.java Created: 30/Jun/2023 06:12 AM Environment: Java 17, Spring Boot 3,
Hibernate 6.2, Oracle and H2 DBs Priority: Major Reporter: Aivis Heniņš (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Encountered an issue with many-to-one associations and @NotFound when migrating to Spring
Boot 3. Incomplete SQL is generated for update and delete statements.
For example, having two entities, user:
@Entity
@Table(name = "users" )
public class User {
@Id
@GeneratedValue
public Long id;
public String name;
public User( String name) {
this.name = name;
}
}
And comments:
@Entity
@Table(name = "comments" )
public class Comment {
@Id
@GeneratedValue
public Long id;
public String text;
@ManyToOne
@JoinColumn(name = "user_id" )
@NotFound(action = NotFoundAction.IGNORE) // <-- issue appears when @NotFound is
added
public User user;
public Comment( String text, User user) {
this.text = text;
this.user = user;
}
}
And following HQL/JPQL statements:
* SELECT c FROM Comment c WHERE c.user = :user
* UPDATE Comment c SET c.text = :text WHERE c.user = :user
* DELETE FROM Comment c WHERE c.user = :user
Selects are working and generate correct SQL - select ... from comments c1_0 left join
users u1_0 on u1_0.id=c1_0.user_id where u1_0.id=?. However update and delete statements
are incomplete (the join part is not included), resulting in invalid SQL - delete from
comments where u1_0.id=?.
When @NotFound is removed from the association then all examples work, the SQL is
generated same way as in Hibernate 5, without join - delete from comments where
user_id=?.
Test case reproducing these examples -
https://github.com/aivish/hibernate-test-case-association-comparisons/tre... , it
contains tests for Hibernate 5 and 6, the update/delete ones are failing in Hibernate 6,
but working in 5.
I see that there are similar issues:
*
https://hibernate.atlassian.net/browse/HHH-16518
*
https://hibernate.atlassian.net/browse/HHH-16615
*
https://hibernate.atlassian.net/browse/HHH-15593
Seems like this provides a bit different use case and simpler test case how to reproduce
the issue, so decided to create a separate issue.
(
https://hibernate.atlassian.net/browse/HHH-16878#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16878#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=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100227- sha1:9e449c4 )