-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Description
Updating entities containing @TenantId produces invalid update query
Example:
@Entity
public class MyEntity {
@Id
@JdbcTypeCode(SqlTypes.CHAR)
private UUID id;
@Column
private String name;
@TenantId
private String tenantId;
}public interface MyRepository extends JpaRepository<MyEntity, UUID> {
@Modifying
@Transactional
@Query("UPDATE MyEntity SET name = :name WHERE id = :id")
void updateNameById(String name, UUID id);
}@Service
public class MyService {
@Autowired
private MyRepository myRepository;
@PostConstruct
public void updateEntity() {
myRepository.updateNameById("Updated Name", UUID.randomUUID());
}
}The resulting SQL is printed as the following:
Hibernate: update MyEntity set name=? where id=? and me1_0.tenantId = ?
In the query we can see that the tenantId is automatically appended and contains the table alias me1_0
However this alias is not set and results in an error
Unrecognized name: me1_0 [at 1:47]
Issue does also occur when directly executing update query with EntityManager.
Valid SQL is produced when using H2 or Postgres
Reproducible code sample:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels