-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Hi,
I stumbled upon an issue, when was updating the project from Spring boot 3.2.x to 3.3.x
With the latest spring boot 3.3.x version (3.3.9), I have observed the following problem in my springboot project that uses spring data jpa to persist againsts MariaDB database.
There are 2 entities with @OneToOne(fetch = FetchType.LAZY)
:
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@Column(name = "some_state")
@Enumerated(EnumType.STRING)
private SomeState someState;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "address_id")
private AddressEntity address;
}
and
public class AddressEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "some_state")
@Enumerated(EnumType.STRING)
private SomeState someState;
@Column(name = "city")
private String city;
}
And there is this JPA Query:
@Modifying
@Query("update UserEntity u set u.someState = 'STATE_TWO' where u.address.city = 'Berlin'")
void setStateTwoForUsersFromBerlin();
When this query method gets called it results in an error:
org.hibernate.exception.ConstraintViolationException: JDBC exception executing SQL [update user ue1_0 join address a1_0 on a1_0.id=ue1_0.address_id set some_state='STATE_TWO' where a1_0.city='Berlin'] [(conn=4) Column 'some_state' in field list is ambiguous] [n/a]
Generated SQL which causes the issue:
Hibernate:
update
user ue1_0
join
address a1_0
on a1_0.id=ue1_0.address_id
set
some_state='STATE_TWO'
where
a1_0.city='Berlin'
Hibernate version that causes this issue is 6.5.3.Final
(for the currently latest 3.3.x (3.3.9))
The issue gets away when Hibernate downgraded to 6.4.10.Final
, and generated SQL looks like this:
Hibernate:
update
user
set
some_state='STATE_TWO'
where
exists(select
1
from
address a1_0
where
a1_0.id=user.address_id
and a1_0.city='Berlin')
Here's a small project to reproduce: https://github.com/RomanCht/spring-boot-jpa-hibernate