I have a structure like this
`
/content/mysite/contacts/johnsmith/jcr:content/contact,
/content/mysite/contacts/john2dave/jcr:content/contact,
/content/mysite/contacts/adamwashingto/jcr:content/contact,
/content/mysite/contacts/janesmith/jcr:content/contact`
...etc, in
/content/mysite/<nameofuser>/jcr:content, there is a property called "pagename",each one has a different value. and in
/content/mysite/<nameofuser>/jcr:content/contact, there is a property called "firstname", of course, each "firstname" has his own name.
Now I want to find all the 'contact' nodes whose "firstname"='john' and those parent nodes jcr:content has a pagename="abc".
How do I write this query in JCR SQL2?
Thank you.
One way of achieving it would be using JOINS and the ISCHILDNODE join conditions of the JCR SQL2
Assuming your jcr:content is of type cq:PageContent and contact is of type nt:unstructured, the query would be
SELECT * FROM [cq:PageContent] as parent
INNER JOIN [nt:unstructured] as child
ON ISCHILDNODE(child, parent)
WHERE ISDESCENDANTNODE(parent, '/content/mysite')
AND child.firstname = 'john'
AND parent.pagename ='abc'
You can also refer to this JCR Query Cheat Sheet for quick reference.
Related
I am using CategoryCollection to get the records of a specific category ID, but the problem is it only loads the exact category for e.g I have parent > child and I have attached child category ID to a record and I select child category, then it shows me the record fine, but if I select parentID, then it does not show the child category record.
$collection = \TYPO3\CMS\Frontend\Category\Collection\CategoryCollection::load(
$categoryID,
true,
'tx_myextension_table_name',
'categories'
);
Is there any built-in way to get the records of all child category if I select parent ID from CategoryCollectionor do I have to write something custom for that?
Unfortunately there is no built-in solution for complex selections like this. You will indeed need to write your own logic which could work like this:
Find categories whose parent is your category
Repeat this recursively for every category found until you don't find any children for each category anymore
Do a custom IN() query with the list of category UIDs
If you have deep category trees, the list of category UIDs could be put in a custom cache. You can use the root category UID or a hash thereof as key. These cache entries should be tagged with sys_category. Alternatively you can add a sys_category_<uid> tag for every category UID in your list. This ensures that whenever something changes about one of the categories, the cache entries are dropped and you can rebuild the list.
I'm new to Hibernate and I encountered a query today:
select new SomeClassDTO(r.id, r.name, r.description, u.id) from ClassA as u
inner join u.data as r where u.email !=?1 and r.name not like '%Blah%
Can you please explain how this query works?
This query takes several fields from a ClassA entity with it's associated data Entity(s) and passes those field values into the constructor for class SomeClassDTO.
As the name of the created object implies, this is a way to take data from multiple associated database-mapped Entities, and construct a Data Transfer Object (DTO) to pass to your presentation layer.
You are essentially creating a 'view' of your database Entities and constructing new objects to hold the records of the result set of that view.
I am trying to develop a query that seeks parents in a table where the fields are parent and child, using lambda syntax or query syntax.
My model is basically
Entities
EntityID
Name
Age
EntityType
EntitiesRelation
EntityParentID [PK, FK, EntityID]
EntityChildID [PK, FK, EntityID]
I know I cannot access the EntitiesRelation table directly (because it is a Join table). I have other queries with join tables, but this case, I couldn't resolve until now.
You should have two navigation properties, Entities1 and Entities11 as you stated, one belongs to the relationship as parent and the other as child.
Look at the designer to which one corresponds each and name them "Parent" and "Children" and you are ready.
Suppose I have a JPQL query like this:
SELECT p
FROM Parent p
LEFT OUTER JOIN p.children child
WHERE p.children IS EMPTY
OR child.x = 'y'
I would like Parent instances returned in any of the following cases:
the Parent has no children
the Parent has at least one child whose x is equal to y
According to the JPA specification, should the query above do what I want? Or must I drag out the EXISTS-and-subquery-and-IN machinery?
Yes, your query will do what you want, no matter the JPA implementation. Personally I don't see any room for doubt, although I can feel what you don't like: that the table children will be probably joined twice. But in my IMHO the JPA implementation should make two DB queries if needed in order to return the correct data.
I am suspecting the method defined to get siblings in the book MongoDB in Action
Every category keeps parent_id that is the parent category id. So sibling categories should have common parent_id.
But to query siblings for a particular category (let's say category['_id'] = C5) book says following:
siblings = db.categories.find({'parent_id': category['_id']});
Returned cursor is obviously not siblings of C5, they are child of C5.
As per my understanding query should be
siblings = db.categories.find({'parent_id': category['parent_id']});
Please comment.
You are correct, and this is fixed in the second printing of the book. See the errata here:
http://manning.com/banker/excerpt_errata.html