You have an entity named Company.
That entity is a
It has a field, clinicPartnershipLabList, which is a field using @JoinTable with an @OneToMany relationship.
@OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "clinic_partnership_lab",
joinColumns = @JoinColumn(name = "clinic_id"),
inverseJoinColumns = @JoinColumn(name = "lab_id")
)
private List<Company> clinicPartnershipLabList;
And it has a field clinicPartnershipLabList, which is a field using @JoinTable with an @OneToOne relationship.
clinicResponsibleLab, which is a field with an @OneToOne relationship.
@OneToOne
@JoinTable(name = "clinic_responsible_lab",
joinColumns = @JoinColumn(name = "clinic_id", referencedColumnName = ),
inverseJoinColumns = @JoinColumn(name = "lab_id")
)
private Company clinicResponsibleLab;
First, the problematic relationship is resolved as @OneToOne, and the
I used Spring Data JPA’s nativeQuery to get the query.
- No error when querying with JPQL.
Below is the error message.
[main] WARN o.h.e.jdbc.spi.SqlExceptionHelper SQL Error: 0, SQLState: S0022
[main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper Column 'lab_id' not found.
The SQL that made the lookup looks like this
Strangely, the error only occurs in OneToOne relationship using native query, please tell me why?
@Query(nativeQuery = true,
value = """
select c.*
from company c
where c.id = 150
"""
)
List<Company> test();
@Query(value = """
select c
from Company c
where c.id= 150
""")
List<Company> test2();
Initially, I checked to see if the mapping of the OneToOne relationship was incorrect, and found that the
I tried adding a ‘referencedColumnName’ field, but that didn’t work.
And I checked that the column names of the table in the DB are in order