Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Teneo Query By Example
Teneo Query By Example [message #93866] Wed, 22 August 2007 00:09 Go to next message
Jason Henriksen is currently offline Jason HenriksenFriend
Messages: 231
Registered: July 2009
Senior Member
Hi Martin,

My team is trying to build a query by example infrastructure and having a
strange scenario. If a field is nullable and set to null the the field does
not appear as a qualifier in the hibernate query. However if the field in
'unset' then the hibernate generated query will include that column as a
qualifer making bad things happened.

So for example my Book could have a 'code' value of A,B or C. I want to
query by example, so I specify the book's 'title' but I leave the 'code'
value as unset.
The generated query includes 'code' in the criteria parameters and since it
doesn't match nothing is returned.
It seems that the column should not appear in the query at all. Do you have
any experience working with EMF/Hibernate queries in this way?

Thanks for any suggestions,

Jason Henriksen.
Re: Teneo Query By Example [message #93898 is a reply to message #93866] Wed, 22 August 2007 06:24 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jason,
I am not sure if I understand your question but Emf can generate an isSet method if you set the
unsettable property of the efeature to true. You can then use this isSet method to check if the
efeature should be added to the query.

gr. Martin

Jason Henriksen wrote:
> Hi Martin,
>
> My team is trying to build a query by example infrastructure and having a
> strange scenario. If a field is nullable and set to null the the field does
> not appear as a qualifier in the hibernate query. However if the field in
> 'unset' then the hibernate generated query will include that column as a
> qualifer making bad things happened.
>
> So for example my Book could have a 'code' value of A,B or C. I want to
> query by example, so I specify the book's 'title' but I leave the 'code'
> value as unset.
> The generated query includes 'code' in the criteria parameters and since it
> doesn't match nothing is returned.
> It seems that the column should not appear in the query at all. Do you have
> any experience working with EMF/Hibernate queries in this way?
>
> Thanks for any suggestions,
>
> 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 #93974 is a reply to message #93898] Wed, 22 August 2007 17:04 Go to previous messageGo to next message
Jason Henriksen is currently offline Jason HenriksenFriend
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 Go to previous message
Martin Taal is currently offline Martin TaalFriend
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 #609503 is a reply to message #93866] Wed, 22 August 2007 06:24 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi Jason,
I am not sure if I understand your question but Emf can generate an isSet method if you set the
unsettable property of the efeature to true. You can then use this isSet method to check if the
efeature should be added to the query.

gr. Martin

Jason Henriksen wrote:
> Hi Martin,
>
> My team is trying to build a query by example infrastructure and having a
> strange scenario. If a field is nullable and set to null the the field does
> not appear as a qualifier in the hibernate query. However if the field in
> 'unset' then the hibernate generated query will include that column as a
> qualifer making bad things happened.
>
> So for example my Book could have a 'code' value of A,B or C. I want to
> query by example, so I specify the book's 'title' but I leave the 'code'
> value as unset.
> The generated query includes 'code' in the criteria parameters and since it
> doesn't match nothing is returned.
> It seems that the column should not appear in the query at all. Do you have
> any experience working with EMF/Hibernate queries in this way?
>
> Thanks for any suggestions,
>
> 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 Go to previous message
Jason Henriksen is currently offline Jason HenriksenFriend
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 Go to previous message
Martin Taal is currently offline Martin TaalFriend
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
Previous Topic:[Teneo] Illegal Argument Exception saving null object enumeration
Next Topic:[EMF-Compare] left and right model
Goto Forum:
  


Current Time: Fri Aug 12 21:47:00 GMT 2022

Powered by FUDForum. Page generated in 0.02721 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top