休眠 - 投影组件

时间:2009-12-28 02:54:28

标签: java hibernate

我有一个具有LatLng组件的Address bean。请告诉我如何投影该组件并将其转换为新类。

谢谢。

2 个答案:

答案 0 :(得分:2)

据我所知,你想为LatLng创建一个单独的类,如下所示。

public class LatLng {
}

然后想要将它包含在您的实体Address bean中,如下所示。

public class Address {
   private LatLng latLng;
}

现在,请查看Custom value types in HibernateMapping custom type in Hibernate

答案 1 :(得分:0)

例如,您可以使用以下标准:

Criteria criteria = session.createCriteria(Cat.class);
criteria.add(Restrictions.like(“description”, “Pap”)
  .addOrder(Order.asc(“description”);

Criteria subCriteria = criteria.createCriteria("kind", "kind");
subCriteria.add(Restrictions.eq("description", "persa"));

Criteria anotherSubCriteria = subCriteria.createCriteria("anAssociation","anAssociation");
anotherSubCriteria.add(Restrictions.eq("attribute", "anything"));

criteria.setResultTransformer(new AliasToBeanResultTransformer(Cat.class));

criteria.crateAlias(“kind.anAssociation”, “kind_anAssociation”);

criteria.setProjections(Projections.projectionList()
  .add(Projections.alias(Projections.property(“id”), “id”))
  .add(Projections.alias(Projections.property(“kind.id”, “kind.id”))
  .add(Projections.alias(Projections.property(“kind.anAssocation.attribute”, “kind.anAssociation.attribute”))

List cats = criteria.list();

但是如果你想保存一些代码,你可以使用Seimos和代码

Filters filters = new Filters();
filters.add(new Filters(“description”, “Pap”)
  .add(new Filter(“description”))
  .add(new Filter("kind.description", "persa"))
  .add(new Filter("kind.anAssociation.attribute", "anything"));
List<Cat> cats = dao.find(filters);

因此,请考虑使用http://github.com/moesio/seimos