Criteria criteria = session.createCriteria(Place.class, "place");
criteria.createAlias("place.addresses", "addresses")
criteria.add(Order.desc("addresses.dataFrom"));
criteria.setProjection(Projections.property("addresses"));
List<Address> addresses = criteria.list();
for (Address address : addresses) {
System.out.println(address.description);
}
如果您想根据地点 ID 查找地址,请使用下面的地址。
Criteria criteria = session.createCriteria(Place.class, "place");
criteria.add(Restrictions.eq("place.id", put the place id here);
criteria.createAlias("place.addresses", "addresses")
criteria.add(Order.desc("addresses.dataFrom"));
criteria.setProjection(Projections.property("addresses"));
List<Address> addresses = criteria.list();
for (Address address : addresses) {
System.out.println(address.description);
}