Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Teneo Query By Example
| |
Re: Teneo Query By Example [message #93974 is a reply to message #93898] |
Wed, 22 August 2007 17:04 |
Jason Henriksen Messages: 231 Registered: July 2009 |
Senior Member |
|
|
Here is an example of constructing a hibernate query by example:
----
ConsumerImpl consumer =ConsumerFactory.INSTANCE.createConsumer() ;
consumerObj.setNameFirst("Terry");
consumerObj.setNameLast("Hamilton");
Criteria criteria = hbSession.createCriteria(consumer.getClass());
criteria.add(Example.create(consumer));
List list = criteria.list();
------
Here is the final query generated by hibernate:
----
select this_.consumer_sk as consumer1_1_0_, this_.isd_lock_ct as isd2_1_0_,
this_.consumer_id as consumer3_1_0_, this_.name_prefix as name4_1_0_,
this_.first_name as first5_1_0_, this_.middle_initial as middle6_1_0_,
this_.last_name as last7_1_0_, this_.name_suffix as name8_1_0_, this_.ssn as
ssn1_0_, this_.date_of_birth as date10_1_0_, this_.gender_cd as
gender11_1_0_, this_.marital_status_cd as marital12_1_0_,
this_.citizenship_ind as citizen13_1_0_, this_.disability_ind as
disability14_1_0_, this_.ethnicity_cd as ethnicity15_1_0_, this_.other_id as
other16_1_0_, this_.other_id_type_cd as other17_1_0_, this_.personal_info as
personal18_1_0_, this_.place_of_birth as place19_1_0_,
this_.prefer_comm_method as prefer20_1_0_, this_.isd_lupd_id as isd21_1_0_,
this_.isd_lupd_ts as isd22_1_0_ from TVSP001.consumer this_ where
(this_.consumer_id=? and this_.first_name=? and this_.last_name=? and
this_.gender_cd=? and this_.marital_status_cd=? and this_.citizenship_ind=?
and this_.disability_ind=? and this_.ethnicity_cd=?
----
You'll notice that things like gender_cd and marital_status_cd are present
in the query, but are not specified in my example object. Whe think that
this is because those fields have default values and so cannot be null. If
a field is left as null, it does not appear in the query which is what we
want. However if a field is 'unset' or cannot be null, this method of
generating a query fails because it is more specific than it should be.
I'm not sure if it's even possible to support this feature with EMF, but it
would be nice to hear a definitive yes/no wether or not this type of query
should work.
Thanks Martin!
Jason Henriksen
|
|
|
Re: Teneo Query By Example [message #94004 is a reply to message #93974] |
Wed, 22 August 2007 21:17 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hibernate allows you to set a Hibernate PropertySelector on the Example created by Example.create
(see the setPropertySelector method). A propertyselector should implement one method:
include(Object propertyValue, String propertyName, Type type)
So you should implement your own propertyselector which checks if the efeature was set. The
propertyname (passed in the include method call) should be the same as the efeature name. So you can
use this to get the efeature and check if the efeature was set on the eobject.
btw, I never used criteria by example or the propertyselector. I found the above by looking at the
Hibernate source code. So I hope it works.
gr. Martin
Jason Henriksen wrote:
> Here is an example of constructing a hibernate query by example:
>
> ----
> ConsumerImpl consumer =ConsumerFactory.INSTANCE.createConsumer() ;
> consumerObj.setNameFirst("Terry");
> consumerObj.setNameLast("Hamilton");
>
> Criteria criteria = hbSession.createCriteria(consumer.getClass());
> criteria.add(Example.create(consumer));
> List list = criteria.list();
> ------
>
> Here is the final query generated by hibernate:
>
> ----
> select this_.consumer_sk as consumer1_1_0_, this_.isd_lock_ct as isd2_1_0_,
> this_.consumer_id as consumer3_1_0_, this_.name_prefix as name4_1_0_,
> this_.first_name as first5_1_0_, this_.middle_initial as middle6_1_0_,
> this_.last_name as last7_1_0_, this_.name_suffix as name8_1_0_, this_.ssn as
> ssn1_0_, this_.date_of_birth as date10_1_0_, this_.gender_cd as
> gender11_1_0_, this_.marital_status_cd as marital12_1_0_,
> this_.citizenship_ind as citizen13_1_0_, this_.disability_ind as
> disability14_1_0_, this_.ethnicity_cd as ethnicity15_1_0_, this_.other_id as
> other16_1_0_, this_.other_id_type_cd as other17_1_0_, this_.personal_info as
> personal18_1_0_, this_.place_of_birth as place19_1_0_,
> this_.prefer_comm_method as prefer20_1_0_, this_.isd_lupd_id as isd21_1_0_,
> this_.isd_lupd_ts as isd22_1_0_ from TVSP001.consumer this_ where
> (this_.consumer_id=? and this_.first_name=? and this_.last_name=? and
> this_.gender_cd=? and this_.marital_status_cd=? and this_.citizenship_ind=?
> and this_.disability_ind=? and this_.ethnicity_cd=?
> ----
>
> You'll notice that things like gender_cd and marital_status_cd are present
> in the query, but are not specified in my example object. Whe think that
> this is because those fields have default values and so cannot be null. If
> a field is left as null, it does not appear in the query which is what we
> want. However if a field is 'unset' or cannot be null, this method of
> generating a query fails because it is more specific than it should be.
>
> I'm not sure if it's even possible to support this feature with EMF, but it
> would be nice to hear a definitive yes/no wether or not this type of query
> should work.
>
> Thanks Martin!
>
> Jason Henriksen
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
| |
Re: Teneo Query By Example [message #609508 is a reply to message #93898] |
Wed, 22 August 2007 17:04 |
Jason Henriksen Messages: 231 Registered: July 2009 |
Senior Member |
|
|
Here is an example of constructing a hibernate query by example:
----
ConsumerImpl consumer =ConsumerFactory.INSTANCE.createConsumer() ;
consumerObj.setNameFirst("Terry");
consumerObj.setNameLast("Hamilton");
Criteria criteria = hbSession.createCriteria(consumer.getClass());
criteria.add(Example.create(consumer));
List list = criteria.list();
------
Here is the final query generated by hibernate:
----
select this_.consumer_sk as consumer1_1_0_, this_.isd_lock_ct as isd2_1_0_,
this_.consumer_id as consumer3_1_0_, this_.name_prefix as name4_1_0_,
this_.first_name as first5_1_0_, this_.middle_initial as middle6_1_0_,
this_.last_name as last7_1_0_, this_.name_suffix as name8_1_0_, this_.ssn as
ssn1_0_, this_.date_of_birth as date10_1_0_, this_.gender_cd as
gender11_1_0_, this_.marital_status_cd as marital12_1_0_,
this_.citizenship_ind as citizen13_1_0_, this_.disability_ind as
disability14_1_0_, this_.ethnicity_cd as ethnicity15_1_0_, this_.other_id as
other16_1_0_, this_.other_id_type_cd as other17_1_0_, this_.personal_info as
personal18_1_0_, this_.place_of_birth as place19_1_0_,
this_.prefer_comm_method as prefer20_1_0_, this_.isd_lupd_id as isd21_1_0_,
this_.isd_lupd_ts as isd22_1_0_ from TVSP001.consumer this_ where
(this_.consumer_id=? and this_.first_name=? and this_.last_name=? and
this_.gender_cd=? and this_.marital_status_cd=? and this_.citizenship_ind=?
and this_.disability_ind=? and this_.ethnicity_cd=?
----
You'll notice that things like gender_cd and marital_status_cd are present
in the query, but are not specified in my example object. Whe think that
this is because those fields have default values and so cannot be null. If
a field is left as null, it does not appear in the query which is what we
want. However if a field is 'unset' or cannot be null, this method of
generating a query fails because it is more specific than it should be.
I'm not sure if it's even possible to support this feature with EMF, but it
would be nice to hear a definitive yes/no wether or not this type of query
should work.
Thanks Martin!
Jason Henriksen
|
|
|
Re: Teneo Query By Example [message #609510 is a reply to message #93974] |
Wed, 22 August 2007 21:17 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hibernate allows you to set a Hibernate PropertySelector on the Example created by Example.create
(see the setPropertySelector method). A propertyselector should implement one method:
include(Object propertyValue, String propertyName, Type type)
So you should implement your own propertyselector which checks if the efeature was set. The
propertyname (passed in the include method call) should be the same as the efeature name. So you can
use this to get the efeature and check if the efeature was set on the eobject.
btw, I never used criteria by example or the propertyselector. I found the above by looking at the
Hibernate source code. So I hope it works.
gr. Martin
Jason Henriksen wrote:
> Here is an example of constructing a hibernate query by example:
>
> ----
> ConsumerImpl consumer =ConsumerFactory.INSTANCE.createConsumer() ;
> consumerObj.setNameFirst("Terry");
> consumerObj.setNameLast("Hamilton");
>
> Criteria criteria = hbSession.createCriteria(consumer.getClass());
> criteria.add(Example.create(consumer));
> List list = criteria.list();
> ------
>
> Here is the final query generated by hibernate:
>
> ----
> select this_.consumer_sk as consumer1_1_0_, this_.isd_lock_ct as isd2_1_0_,
> this_.consumer_id as consumer3_1_0_, this_.name_prefix as name4_1_0_,
> this_.first_name as first5_1_0_, this_.middle_initial as middle6_1_0_,
> this_.last_name as last7_1_0_, this_.name_suffix as name8_1_0_, this_.ssn as
> ssn1_0_, this_.date_of_birth as date10_1_0_, this_.gender_cd as
> gender11_1_0_, this_.marital_status_cd as marital12_1_0_,
> this_.citizenship_ind as citizen13_1_0_, this_.disability_ind as
> disability14_1_0_, this_.ethnicity_cd as ethnicity15_1_0_, this_.other_id as
> other16_1_0_, this_.other_id_type_cd as other17_1_0_, this_.personal_info as
> personal18_1_0_, this_.place_of_birth as place19_1_0_,
> this_.prefer_comm_method as prefer20_1_0_, this_.isd_lupd_id as isd21_1_0_,
> this_.isd_lupd_ts as isd22_1_0_ from TVSP001.consumer this_ where
> (this_.consumer_id=? and this_.first_name=? and this_.last_name=? and
> this_.gender_cd=? and this_.marital_status_cd=? and this_.citizenship_ind=?
> and this_.disability_ind=? and this_.ethnicity_cd=?
> ----
>
> You'll notice that things like gender_cd and marital_status_cd are present
> in the query, but are not specified in my example object. Whe think that
> this is because those fields have default values and so cannot be null. If
> a field is left as null, it does not appear in the query which is what we
> want. However if a field is 'unset' or cannot be null, this method of
> generating a query fails because it is more specific than it should be.
>
> I'm not sure if it's even possible to support this feature with EMF, but it
> would be nice to hear a definitive yes/no wether or not this type of query
> should work.
>
> Thanks Martin!
>
> Jason Henriksen
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Goto Forum:
Current Time: Wed Jan 15 08:23:37 GMT 2025
Powered by FUDForum. Page generated in 0.03552 seconds
|