当我在 hql 中使用构造函数作为打击时:
控制台打印出 20 条 sql 语句。不是我预期的一条。但是当构造函数只包含表 A 和 B 的字段时,它只执行一个 sql。我想知道为什么会这样。感谢您的帮助!
抱歉不清楚,这里有一些细节:
List list = baseDao.findListByQL("select new List(a,b) from A a,B b where a.id=b.id");
方法“findListByQL”刚刚使用“Query query = entityManager.createQuery(jpql);”调用了一个方法 得到一些结果。
和休眠打印一些sql如下:
Hibernate: select a0_.id as col_0_0_, b1_.id as col_1_0_ from dbo.A a0_, dbo.B b1_ where a0_.id=b1_.id
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
Hibernate: select a0_.id as id103_0_, a0_.name as name103_0_ from dbo.A a0_ where a0_.id=?
Hibernate: select b0_.id as id106_0_, b0_.score as score106_0_ from dbo.B b0_ where b0_.id=?
但是当 "new List" 构造函数使用一些字段属性如 "new List(a.name,b.score)" 时,它只打印一个 sql。