我有一个国家课程,
public class Country implements java.io.Serializable
{
private Integer countryId;
private String countryName;
private boolean status;
private Set<State> states = new HashSet<>(0);
..
..
(getters and setters)
}
州级,
public class State implements java.io.Serializable
{
private Integer stateId;
private Country country;
private String stateName;
private boolean status;
..
..
(getters and setters)
}
如何通过编写用于获取Country类的函数来获取状态为true的那些状态,即
public List<Country> getCountryList()
{
try
{
List<Country> countryList = new ArrayList<>();
Criteria crit HibernateUtil.createCriteria(Country.class,"country").add(Restrictions.eq("status", true));
crit.addOrder(Order.asc("countryName"));
List<?> list = crit.list();
Iterator<?> iterator = list.iterator();
while (iterator.hasNext())
{
Country country = (Country)iterator.next();
countryList.add(country);
}
return countryList;
}
}
我需要在上面的函数中做出哪些更改,以便如果我从country对象中获取状态集,我只得到那些状态为true的状态。
答案 0 :(得分:0)
尝试这可能适合你。
public class Country implements java.io.Serializable
{
private Integer countryId;
private String countryName;
private boolean status;
@Where(子句=&#34;状态=真&#34)
private Set states = new HashSet&lt;&gt;(0);
..
..
(getters and setters)
}