[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3582) Conceptual Queries extension for HSQL:Queries are too sensitive to model changes

Francisco Peredo (JIRA) noreply at atlassian.com
Sat Nov 1 01:00:04 EDT 2008


Conceptual Queries extension for HSQL:Queries are too sensitive to model changes
--------------------------------------------------------------------------------

                 Key: HHH-3582
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3582
             Project: Hibernate Core
          Issue Type: New Feature
          Components: query-criteria, query-hql
            Reporter: Francisco Peredo


When a query is written in JPAQL or HSQL, it still depends to much on the domain model (I think HSQL could be extended to support Conceptual Queries). 

For example, lets say you want to: 

Find each white cat that lives in a house with doors made of wood 

A cat is of one color, it lives in one house, a house can have 1 door and the door can be made of 1 material 

So, the query in HSQL looks like this: 

select c from Cat c where c.color="white" and c.house.door.material.name = "wood" 

But then, lets say our customer changes the requirements: 

Find each white cat that lives in a house with doors made of wood 

A cat is of one color, it lives in many houses, a each house has many  doors and the door is made of  one or more materials (for example half glass, half wood) 

Since our relationships are now @OneToMany so we write their names in plural, and we are newbies in HSQL we try doing this (and it, of course does not work):

select c from Cat c Cat c where c.color="white" and c.houses.doors.materials.name = "wood" 

Now, we can of course solve this problem using subqueries and the exists keyword, but that makes the resulting query way more complex, and even if the above worked, it still is a different query, but, in our english example, the query didn't change:

Find each white cat that lives in a house with doors made of wood 

So, why we can not write in HSQL something like:

select c from Cat c where c with color= "white" and lives in House has Doors made of Material with name = "wood" 

That way the query wouldn't have to change even if the multiplicity of the relationships changed. Of course now the question is, from where do I get the "with","lives in", "has", "made of" and "with" well, simple:

The with operator is available for each non @Entity member of the class (for strings, integers, etc).
For relationships with other entities we just add the conceptual name of the relationship name as an attribute in the @OneToMany or @ManyToOne annotations:
Example:

public class Cat{

@Column

private String color;

@OneToMany(mappedBy="cat", conceptualName="lives in ")

private Set<House> houses;

}

What do you think? 



-- 
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