In Service
When I use print the keys that output null
but print the ids that is correct
please tell me why
I’m sure the database has data
orderBean
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "`Order`")
public class OrderBean {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String orderNumber;
private String account;
public String getOrderNumber() {
return orderNumber;
}
public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
}
//Getters and Setter ....
}
orderDAO
public interface OrderDAO extends JpaRepository<OrderBean, Long>{
@Query(value = "SELECT * FROM `order` WHERE account=?", nativeQuery = true)
public List<OrderBean> findOrderByAccount(String account);
}
orderService
public List<OrderBean> findOrderByAccount(String account) {
List<OrderBean> orderBeanList = orderDAO.findOrderByAccount(account);
for(OrderBean orderBean : orderBeanList) {
String key = orderBean.getOrderNumber();
//output:null null
String id = orderBean.getId();
//output:1 2
}
2
Answers
You can have a look at this example, it looks like query should be:
Try this Query.
you can also try to change the Table name from `Order` to just Order
orderService
try this it might solve your error.