[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3646) implement Criteria API querying of collection-of-component
Olivier Dedieu (JIRA)
noreply at atlassian.com
Wed Jan 20 08:20:39 EST 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=35282#action_35282 ]
Olivier Dedieu commented on HHH-3646:
-------------------------------------
David, Thank you very much for this wonderful patch.
I'v applied your patch (hib-core-query-collection-of-elements-3_3_1-ver6.patch) on Hibernate 3.3.2-GA.
It works great.
As I didn't know how to query against a particular value of the collection I've explored your patch and used the restriction on the CollectionPropertyNames.COLLECTION_ELEMENTS (i.e. "elements").
I've tested with a query against a collection of values, with a code similar to the following one:
session.createCriteria(User.class).createCriteria("emails").add(Restrictions.eq(CollectionPropertyNames.COLLECTION_ELEMENTS, "olivier at example.com"));
I checked the SQL query and it contains the inner join on the collection. It produces something like :
select ... from user this_ inner join user_emails user_emails1_ on this_.ROW_ID=user_emails1_.J_ITEM_ID where user_emails1_.J_VALUE='olivier at example.com'
Is it the correct way to do that ?
I hope your patch (or something similar) will be added in the next release of Hibernate.
> implement Criteria API querying of collection-of-component
> ----------------------------------------------------------
>
> Key: HHH-3646
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3646
> Project: Hibernate Core
> Issue Type: Patch
> Components: query-criteria
> Affects Versions: 3.2.6
> Environment: hibernate 3.2.6, tested on linux 64-bit openjdk 1.6 (jdk1.5 for compiling). mapping created under annotations 3.3.1ga
> Reporter: David Mansfield
> Attachments: hib-core-query-collection-of-elements-3_2_6-ver2.patch, hib-core-query-collection-of-elements-3_2_6.patch, hib-core-query-collection-of-elements-3_3_1-ver5.patch, hib-core-query-collection-of-elements-3_3_1-ver6.patch
>
> Original Estimate: 1 day
> Remaining Estimate: 1 day
>
> the attached patch implements a first cut, extremely rough, yet working extension of the CriteriaQueryTranslator class to allow for querying of properties of components inside a collection, or querying properties of associated elements of components inside a collection. eg for
> * code is lightly tested, this example is for illustrative purposes only
> * i use annotations, so my example is expressed in those terms, and i've only tested with mappings generated via annotations, however, the modifications only apply to the core.
> @Entity
> class Order {
> @Id
> String id;
> @CollectionOfElements
> Set<OrderLineItem> lineItems;
> }
> @Embeddable
> class OrderLineItem {
> @ManyToOne
> Product product;
> Integer quantity;
> }
> @Entity
> class Product {
> String name;
> }
> Then we can now do:
> Criteria c = session.createCriteria(Order.class)
> .createCriteria("lineItems")
> .add(Restrictions.gt("quantity", new Integer(1))
> .list();
> or
> Criteria c = session.createCriteria(Order.class)
> .createCriteria("lineItems")
> .createCriteria("product")
> .add(Restrictions.like("name", "cake%")
> .list();
--
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