实体:
@Entity(name = "ap_order_paid")
@Component
public class ApOrderPaid {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Long order_number;
@Transient
private Long invoiceNumber;
private Long cheqe_number;
//getter setter
}
public class Orders {
private long order_number;
private String invoice_number;
}
我在mysql编辑器中运行下面的查询,它正在工作
select
v.order_number,
v.id,
o.invoice_number as invoiceNumber
from ap_order_paid as v, orders o
where v.cheqe_number like '%1234%' and v.order_number = o.order_number
但是当我在Spring和 @Query
不提供发票号码数据的注解
@Query(value="select v.*, o.invoice_number from ap_order_paid as v, orders o where v.cheqe_number like %?1% and v.order_number = o.order_number", nativeQuery = true)
List<ApOrderPaid> getOrderTaskPaidByCheqNo(String cheqe_number);
2条答案
按热度按时间7ivaypg91#
您没有在任何列上提到任何类型的@column注解。您正在尝试获取“invoicenumber”,这是一个“临时”字段。使用适当的注解,以便hibernate能够用实体对象Mapdb列。
9gm1akwq2#
将关联Map为
@ManyToOne
这样地:使用hql/jpql查询,如下所示: