当我使用构造在HQL吹塑:HQL像 “选择新的构造”,在休眠casues mulitiple SQL执行
控制台打印出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” 刚打电话使用方法 “查询查询= 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=?
但是,当“新目录”构造函数中使用的一些字段属性,如“新名单(a.name,b.score)”,它只能打印一个SQL。
你的问题有点不清楚,发布两个查询与各自的结果。另外,'top'不是JPQL中的保留关键字,您不是创建本地查询,这是您的工作代码。 –
感谢您的关注。我添加了一些细节,希望已经足够清晰。 – Taurus