2
我有一个简单的POJO:SqlResultSetMapping在POJO
我想标题列映射到标题字段:
@SqlResultSetMapping(
name = "ownerSaleMapping",
classes = {
@ConstructorResult(
targetClass = OwnerSale.class,
columns = {
@ColumnResult(name = "title", type = String.class)
}
)
}
)
@NamedNativeQuery(name = "ownerSaleReport", query = "SELECT title FROM content where id=:contentId", resultSetMapping = "ownerSaleMapping")
public class OwnerSale {
public OwnerSale() {
}
private String title;
public OwnerSale(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
我的仓库接口:
public interface OwnerSaleRepository extends JpaRepository<OwnerSale, Long> {
List<OwnerSale> ownerSaleReport(@Param("contentId") Long ownerId);
}
但是,当我” m使用:
List<OwnerSale> sales = ownerSaleRepository.ownerSaleReport(6);
I g加时赛此错误:
IllegalArgumentException: Not an managed type: class domain.owner.OwnerSale
但我需要OwnerSale
是POJO
不是Entity
。
解决方案是什么?
其实我不知道,你可以使用未在此处,实体类'JpaRepository ' –
AFAIK添加注释不强制类不成为POJO [链接](https://spring.io/understanding/POJO)。奇怪的是你可以添加'@ SqlResultSetMapping'和'@ NamedNativeQuery',但不能添加'@ Entity'和'@ Id' –