|
Re: [CDO/Hibernate] Query withing one resource [message #1383952 is a reply to message #1370111] |
Tue, 27 May 2014 11:54 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hey,
Later reply... Teneo automatically adds a resourceId property to each object. So you can query using it. I never tried
it though, so there could be obstacles:
CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where resourceId=:id");
cdoQuery.setParameter("id", resourceCDOId);
gr. Martin
On 21-05-14 00:02, Evgeny Karataev wrote:
> Hello,
>
> CDOQuery allows to query, for example, for all instances of an object in the whole repository. For example:
>
> CDOQuery cdoQuery = transaction.createQuery("hql", "from Product");
>
> The code above will search for all products in all resources.
>
> Is it possible to perform a CDOQuery which will search only within a given (by resource id) resource?
> I have two ideas but I am not sure if that is possible or there is other way:
> 1) Somehow provide resource id in the query, e.g.:
>
> CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where reseource_id = test1");
>
> 2) Or create CDOQuery on resource object.
>
> Thank you.
>
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
|
|
|
|
Re: [CDO/Hibernate] Query withing one resource [message #1386209 is a reply to message #1383967] |
Sat, 14 June 2014 21:48 |
Evgeny Karataev Messages: 18 Registered: May 2014 |
Junior Member |
|
|
Hello Martin,
I just tried the approach that you've suggested. And it seems that it works. I was able to query withing one resource by using query like this one:
CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where resourceId=:id");
cdoQuery.setParameter("id", resourceCDOId);
However, what I've noticed is that for some EClasses from my ecore model corresponding tables in my MySQL database have null value in the resource_id column, but has some value in the container_id column, while for other EClasses, in the corresponding tables resource_id value is set correctly.
This happens for following situation.
For example, I have Class1 in the ecore model having an attribute A that is 0 or more references of Class2. Then in my MySQL database I have corresponding table for Class1 with resource_id values set correctly and nulls in container_id, and corresponding table for Class2 will nulls in the resource_id column and some values in the container_id
Using the query above, I can successfully query for the instances of Class1 for a given resource_id, but not for Class2. I assume I can probably use the container_id columns and perform a join to get all instances of Class2.
Is the join the only way?
Thank you.
|
|
|
Re: [CDO/Hibernate] Query withing one resource [message #1386238 is a reply to message #1386209] |
Sun, 15 June 2014 20:21 |
Erdal Karaca Messages: 854 Registered: July 2009 |
Senior Member |
|
|
This is due to EMF's nature of modeling associations: an object is either contained in a resource (resource_id is set) OR it is part of another object which is its container (container_id is set), but not both.
Evgeny Karataev wrote on Sat, 14 June 2014 23:48Hello Martin,
I just tried the approach that you've suggested. And it seems that it works. I was able to query withing one resource by using query like this one:
CDOQuery cdoQuery = transaction.createQuery("hql", "from Product where resourceId=:id");
cdoQuery.setParameter("id", resourceCDOId);
However, what I've noticed is that for some EClasses from my ecore model corresponding tables in my MySQL database have null value in the resource_id column, but has some value in the container_id column, while for other EClasses, in the corresponding tables resource_id value is set correctly.
This happens for following situation.
For example, I have Class1 in the ecore model having an attribute A that is 0 or more references of Class2. Then in my MySQL database I have corresponding table for Class1 with resource_id values set correctly and nulls in container_id, and corresponding table for Class2 will nulls in the resource_id column and some values in the container_id
Using the query above, I can successfully query for the instances of Class1 for a given resource_id, but not for Class2. I assume I can probably use the container_id columns and perform a join to get all instances of Class2.
Is the join the only way?
Thank you.
|
|
|
Powered by
FUDForum. Page generated in 0.02534 seconds