我有两张桌子,Table CustomerID | CustomerNumber | Name | City | PhoneNumberTable AccountsID | CustomerNumber | AccountNumber | Bank两个表的关系是CustomerNumber我的客户映射public class Customer { @Id @Column(name = "ID") private Integer ID; @Column(name = "CustomerNumber") private Integer customerNumber; @Column(name = "Name") private String name; @Column(name = "City") private String city; @Column(name = "PhoneNumber") private Integer phoneNumber; @OneToMany(fetch = FetchType.LAZY, mappedBy = "customerNumber") private Collection<Account> accounts;}和帐户映射public class Account { @Id @Column(name = "ID") private Integer ID; @JoinColumn(name = "CustomerNumber", referencedColumnName="CustomerNumber") @ManyToOne(fetch = FetchType.LAZY) private Customer customer; @Column(name = "AccountNumber") private Integer accountNumber; @Column(name = "Bank") private String bank;}函数 i DAOpublic SearchResult listByCriteria(Customer object, int maxResults, String sortProperty, boolean ascending) { SearcResult result = new SearchResult(); int resultSize = 0; Criteria customerCriteria = ((Session)em.getDelegate()).createCriteria(Customer.class); if(maxResults > 0) { customerCriteria.setMaxResults(maxResults); } try { if(object != null) { customerCriteria = QueryHelper.getCustomerCriteria(object, customerCriteria, ""); resultSize = QueryHelperUtil.countResults(customerCriteria); result.setSize(resultSize); customerCriteria.setFirstResult(index); QueryHelperUtil.sortResults(customerCriteria, sortProperty, ascending); result.setList(customerCriteria.list()); } } } }}现在我只想搜索拥有银行账户的客户。我想在 Hibernate 中设置一个标准。但我就是不知道该怎么做?搜索时,您可以输入客户编号、客户姓名、电话号码和/或城市,然后选择要显示的结果数量。起初,我以为我可以编写一个命名查询,但随后您就拥有了搜索结果编号和在不同列上对结果进行排序的功能。我在这里搜索并查看了不同的类似问题,但我无法让它发挥作用。我试图在按条件列出客户的功能中添加帐户条件,但它不起作用,我不知道它是否与帐户作为集合有关?有人可以帮我吗?
添加回答
举报
0/150
提交
取消