Spring+Hibernate3的关联查询

    技术2022-05-11  12

    Spring+Hibernate3的框架中用到了关联查询 表User:Address是一对多的关系 UserBean中有一个addresses的Set 现在要查询出这样的User,拥有Address中门牌doorplate为"642"的User, 现在DB中只有一个这样的User,这个User拥有门牌doorplate为"642"的Address五个~~ 创建DetachedCriteria 的语句如下: DetachedCriteria detachedCriteria = DetachedCriteria.forClass(User. class); detachedCriteria.createCriteria( "addresses" ).add(Restrictions.like( "doorplate" , "642" ));实际查询语句如下: List list = getHibernateTemplate().findByCriteria(queryCriteria); 理论上查询出来的list应该User的list是1总结如下1:DetachedCriteria addressCriteria = DetachedCriteria.forClass(User.class).createCriteria("addresses");addressCriteria.add(Restrictions.eq("doorplate","642")):2:DetachedCriteria addressCriteria = DetachedCriteria.forClass(User.class).createAlias("addresses", "a");addressCriteria.add(Restrictions.eq("a.doorplate","642")):     

    最新回复(0)