[英]JpaRepository with custom Query and Composite Primary Key: error unknown column
I have a SQL Server entity with a Composite Primary Key.我有一个带有复合主键的 SQL 服务器实体。
That is the Entity:那就是实体:
@Entity
@Table(name = "plz", schema = "dbo")
@IdClass(plzId.class)
public class Plz {
@Id
@Column(name = "plz", columnDefinition = "NCHAR(5)")
private String plz;
@Id
@Column(name = "ort", columnDefinition = "NCHAR(30)")
private String ort;
@Column(name = "gueltigbis")
private Date gueltigBis;
@Column(name = "gueltigvon")
private Date gueltigVon;
@Id
@Column(name = "value", columnDefinition = "NCHAR(5)")
private String value;
}
and this is ID Class:这是 ID Class:
@Data
@EqualsAndHashCode
public class plzId implements Serializable {
private String plz;
private String ort;
private String value;
}
That is the JpaRepository那就是 JpaRepository
public interface PlzRepository extends JpaRepository<Plz, PlzId> {
@Query(value = "SELECT value, ort FROM dbo.plz WHERE plz = :plz AND gueltigvon <= :bezugsdatum AND gueltigbis >= :bezugsdatum",
nativeQuery = true
)
List<Plz> findByPlzDatum(@Param("plz") String plz, @Param("bezugsdatum") Date bezugsdatum);
}
But when this Query is executed I get an error: Invalid Column name: plz但是当执行这个查询时,我得到一个错误:无效的列名:plz
Finally I got the solution:-) The select wasn't returing the full key / object. Validation on the object failed and there was not suitable constructor present.最后我得到了解决方案:-) select 没有返回完整密钥/object。object 上的验证失败并且不存在合适的构造函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.