我在我的jparepository里有一个类似的问题
@Query("select new com.x.airlinesystem.dto.ticket.TicketPriceDTO((select count(t) from Ticket t where t.flight=:flightId and t.ticketStatus=:ticketStatus),f.capacity,f.price) from Flight f where f.id = :flightId")
TicketPriceDTO findPriceInfo(@Param("flightId") Long flightId,
@Param("ticketStatus") TicketStatus ticketStatus);
我的dto如下所示;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TicketPriceDTO implements Serializable {
private Integer sold;
private Integer capacity;
private BigDecimal price;
}
最后我的票证状态是;
public enum TicketStatus {
SOLD, RETURNED
}
当我编译这个项目时,我得到如下错误;
原因:java.lang.illegalargumentexception:org.hibernate.hql.internal.ast.querysyntaxexception:无法在类[com.x.airlinesystem.dto.ticket.ticketpricedto]上找到相应的构造函数。预期参数为:long,int,java.math.bigdecimal[select new com.x.airlinesystem.dto.ticket.ticketpricedto((select count(t)from com.x.airlinesystem.entity.ticket t where t.flight=:flightid and t.ticketstatus=:ticketstatus),f.capacity,f.price)from com.x.airlinesystem.entity.flightf where f.id=:flightid]
2条答案
按热度按时间vbopmzt11#
只是一种预感,但确实如此
(select count(t) from Ticket t where t.flight=:flightId and t.ticketStatus=:ticketStatus
回来很久了?也许改变就足够了
private Integer sold;
至private Long sold;
?taor4pac2#