How to return an entity with chosen columns using Criteria

前端 未结 3 962
感动是毒
感动是毒 2020-12-13 13:51

I\'m really new with Hibernate. I want a List using hibernate criteria, but only with fields User id and name filled up. Is that possible? Something

3条回答
  •  庸人自扰
    2020-12-13 14:18

    Typically you don't want to partially load the properties of an object. But if you must, see this:

    http://docs.jboss.org/hibernate/stable/core/manual/en-US/html/performance.html#performance-fetching-lazyproperties

    For plain reporting-like behaviour you could use entity queries:

    sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class);
    

    http://docs.jboss.org/hibernate/stable/core/manual/en-US/html/querysql.html#d0e17633

提交回复
热议问题