人
我正面临这个问题一天,我找不到解决方案。
我有这种情况:
和这段代码,我的实体Ticket.java:
@Entity
@Table(name = "tickets")
@SqlResultSetMapping(
name="SummaryReport",
classes=@ConstructorResult(
targetClass=ValidatedTicketsVO.class,
columns={@ColumnResult(name="quantity",
type=BigInteger.class),
@ColumnResult(name="quarter", type=String.class)
}))
@NamedNativeQuery(
name="Ticket.findShowSummaryReport",
query="SELECT COUNT(*) AS quantity, DATE_FORMAT( FROM_UNIXTIME(UNIX_TIMESTAMP(validation_time) - UNIX_TIMESTAMP(validation_time)%(15*60)), \"%d/%m/%Y %H:%i\" ) AS quarter " +
" FROM tickets " +
" WHERE show_id = :showId " +
" GROUP BY quarter " +
" ORDER BY quarter ")
public class Ticket implements Serializable {
我也尝试使用@EntityResult而不是@ConstructorResult:
@SqlResultSetMapping(
name="SummaryReport",
entities=@EntityResult(
entityClass=ValidatedTicketsVO.class,
fields={@FieldResult(name="quantity", column="quantity"),
@FieldResult(name="quarter", column="quarter")
}))
但我得到了同样的错误。
我的POJO / VO类查询结果必须映射到:
import java.math.BigInteger;
public class ValidatedTicketsVO {
private BigInteger quantity;
private String quarter;
public ValidatedTicketsVO(BigInteger quantity, String timeQuarter) {
super();
this.quantity = quantity;
this.quarter = timeQuarter;
}
[ getters and setters ]
}
PS:字段数量最初被定义为Integer,但是当我得到一个[java.math.BigInteger]异常时,我将其更改为Long,现在更改为BigInteger以查看它是否解决了我的问题,但仍然是相同的。
这是我的Repository方法:
List<ValidatedTicketsVO> findShowSummaryReport(@Param("showId") Long showId);
查询执行得很好,我看不到任何其他日志而不是查询本身。我在日志中没有异常,但是当我尝试通过Postman执行它时我得到了这个响应:
{
"code": 5001,
"description": "Unexpected server error",
"timestamp": 1499782989890,
"errors": 1,
"fieldErrors": [
{
"field": "",
"message": "No converter found capable of converting from type [java.math.BigInteger] to type [br.com.company.validator.model.entity.vo.ValidatedTicketsVO]"
}
]
}
当我在Eclipse上调试它时,当我调用此方法时会发生异常:
List<ValidatedTicketsVO> list = repository.findShowSummaryReport(showId);
有人可以帮助我吗?