This is the second option I mentioned.
By doing this I won't get elements of class A (assuming these elements
are considered having field2 = null).
It would probably be clearer with a UI example :
The user gets this table :
Class field1 field2
A Paris
A London
B New York NY
B Los Angeles CA
He clicks on the field2 column header to sort by state, so he would
expect :
Class field1 field2
A Paris
A London
B Los Angeles CA
B New York NY
If the sorting is done only on elements of the class B, the user will
get this result :
Class field1 field2
B Los Angeles CA
B New York NY
That seems very strange to get less results when you sort a table on a
field that on the other...
Why don't you make "from B b order by b.field2" ?
Let's say we have the following (simplified) mapping :
<class name="A" table="T">
<property name="field1" type="string"/>
<subclass name="B">
<property name="field2" type="string"/>
</subclass>
</class>
Now we can execute any HQL query on the class A using the field1, for
example
"from A a where a.field1 like 'anything%'" or "from A a order by a.field1"
The problems come when we want to use the field2 with the same queries.
Of couse in simple SQL it is possible to do
select * from T order by field2
But in HQL, "from A a order by a.field2" rightly fails because field2 is
not defined
for class A.
This causes problems in sortable or filtered data tables where the user
can sort or filter
by any column he wants.
There is currently only two options :
- allowing to sort only on columns of class A : possible but my users
won't be really happy
- "casting" the query to class B when the user sorts on a column of
class B : that means that the results
count of the query is not the same when it is sorted than when it is
not ; it completely breaks the
semantics of sorting/filtering
I understand it does not follow the OO approach of HQL but it would be
really useful to have an additional
syntax to allow using fields of the subclass in HQL queries, something
like "select a from A+ a order by a.field2",
or maybe an option in the Query interface like
query.setUseInheritedProperties(true).
What do you think of this ?
Note : this is an extension of the JIRA HB-792 and could allow to
resolve this case in a better way
William
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel
|