-
Notifications
You must be signed in to change notification settings - Fork 692
Closed
Labels
type: documentationA documentation updateA documentation update
Milestone
Description
We have the following behavior.
There is a class that is structured like this:
@Entity
@Table(name = "my_entity")
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long pk;
private Long id;
private String name;
public MyEntity() {
}
}
The corresponding repository looks like this and contains a function "existsById":
@Repository
public interface MyEntityRepository extends CrudRepository<MyEntity, Long> {
boolean existsById(Long id);
boolean existsByIdAndName(Long id, String name);
}
Suppose the database contains the following data record:
pk🔑 | id | name |
---|---|---|
1 | 204 | Name1 |
2 | 2830 | Name2 |
3 | 52235 | Name3 |
In our case the following behavior occurred:
existsById(204L) -> false
existsById(2L) -> true
existsByIdAndName(204L, "Name1") -> true
The behavior that was expected was:
The identifier Id in the function name "existsById" refers exclusively to the attribute of the class and is not internally reserved for the primary key. Accordingly, every query should only target this attribute without exception.
SpringBoot-Starter-Data-JPA-Version: 3.3.3
Metadata
Metadata
Assignees
Labels
type: documentationA documentation updateA documentation update