[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2307) Optimize select new query calls like "select new Holder(entity, entity.something) ..." so the parser does not treat them as shallow
Matt Wheeler (JIRA)
noreply at atlassian.com
Wed Dec 13 12:38:05 EST 2006
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2307?page=comments#action_25628 ]
Matt Wheeler commented on HHH-2307:
-----------------------------------
Thanks for the help. I'll update my forum post with your comments - http://forum.hibernate.org/viewtopic.php?p=2326246#2326246.
> Optimize select new query calls like "select new Holder(entity, entity.something) ..." so the parser does not treat them as shallow
> -----------------------------------------------------------------------------------------------------------------------------------
>
> Key: HHH-2307
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2307
> Project: Hibernate3
> Type: New Feature
> Components: query-hql
> Versions: 3.2.0.ga
> Environment: Hibernate Version: 3.2.0ga
> Database platform: Oracle 9.2, HSQLDB 1.7.3.3, and Derby 10.2.1.6
> Reporter: Matt Wheeler
> Priority: Minor
>
>
> Using the JPA implementation, and the following named query:
> @NamedQuery(name=Country.COUNTRIES_AS_SELECT_ITEMS,
> query="select new javax.faces.model.SelectItem(c, c.name) from Country c")
> Which is called from the following method:
> public List<SelectItem> getAllCountriesAsSelectItems() {
> return entityManager.createNamedQuery(Country.COUNTRIES_AS_SELECT_ITEMS).getResultList();
> }
> the following SQL is generated:
> Hibernate: select country0_.id as col_0_0_, country0_.name as col_1_0_ from Country country0_
> Hibernate: select country0_.id as id3_0_, country0_.name as name3_0_ from Country country0_ where country0_.id=?
> Hibernate: select country0_.id as id3_0_, country0_.name as name3_0_ from Country country0_ where country0_.id=?
> Hibernate: select country0_.id as id3_0_, country0_.name as name3_0_ from Country country0_ where country0_.id=?
> Hibernate: select country0_.id as id3_0_, country0_.name as name3_0_ from Country country0_ where country0_.id=?
> Hibernate: select country0_.id as id3_0_, country0_.name as name3_0_ from Country country0_ where country0_.id=?
> Assuming that we have 5 countries in the database, calling the method above would result in 6 queries. The first query appears to get all of the ids, and the next 5 queries appear to retrieve the objects by id.
> However, if we change the query to:
> "select new javax.faces.model.SelectItem(c.name) from Country c" and only select an attribute of country, instead of an attribute of the country and the country entity as well, it will only issue 1 query
> I was just wondering if this could be optimized so that there are not n+1 queries in the new Holder(entity, enity.a) instance
> Just for reference: As per issue HHH-544 Select new n+1 queries, Gavin responded that the parser treats all select new calls as shallow, as is manifest in the above example.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list