[hibernate-dev] 6.0 - Session#createFilter

Gunnar Morling gunnar at hibernate.org
Tue Jan 3 06:31:22 EST 2017


2017-01-02 15:27 GMT+01:00 Steve Ebersole <steve at hibernate.org>:

> The alternative atm is to directly query against the owning entity or
> directly against the element.  Granted that last one assumes that the
> element defines a mapped reference back to the owner to be able to apply
> the restriction based on the FK, but that's the more normal mapping anyway.
>

I realize now that Session#createFilter() is only geared towards
collections. So are you suggesting to only remove that method, but keep
@Filter/@FilterDef?

I've never used filters myself, but my understanding always was that it's
meant for filtering out records on a global level. E.g. to only select
enabled records (by means of an "enabled" flag present for all entities)
without having to adjust each and every query for that.

When used in that way, taking away filters altogether may be quite
disruptive. But it's not clear to me whether that's actually what you are
suggesting.

So e.g., if you have a filter like: `session.createFilter(
> customer.getOrders(), "orderDate < currentDate() - {3 months}" )`, instead
> you'd do: `select elements( c.orders ) from Customer c join c.orders where
> c.id = :customerId and o.orderDate < currentDate() - {3 months}` or
> `select o from Order o where o.customer = :customerId and o.orderDate <
> currentDate() - {3 months}`.
>
> Ultimately I'd also like to see "stream queries".  This would take 2 forms:
>
>    1. Session#stream( Order.class )...
>    2. customer.getOrders().stream()... (this works because
>    customer.getOrders() is a PersistentCollection and we'd control the
>    stream() impl)
>
>
> The reasons for removing it are:
>
>    1. It dirties the HQL grammar.  A valid filter string is literally""
>    (empty String) which means that the grammar needs to allow for that.
>    2. IMO it is a clunky API
>    3. I am pretty sure noone uses it.  Not to pick on Christian, but he
>    is a pretty advanced user and even he did not understand its use which
>    speaks both to its obscurity as well as its clunkiness.
>
>
> On Mon, Jan 2, 2017 at 7:08 AM Gunnar Morling <gunnar at hibernate.org>
> wrote:
>
>> > I plan on removing Session#createFilter.  There are numerous reasons
>> why
>> which I can discuss if anyone is interested in exploring this.
>>
>> I'm curious, what are the reasons for removing it? And if we remove it,
>> what's the alternative for people to use?
>>
>>
>> 2016-12-31 21:00 GMT+01:00 Steve Ebersole <steve at hibernate.org>:
>>
>> As I have not been hearing hardly any feedback on these 6.0 design
>> questions I have been trying to start, I'll be doing something different
>> in
>> this and any additional emails.. I'll state what I propose to do and if
>> anyone has issue with it they can make a counter proposal.  Otherwise I
>> plan on following through with my proposal.
>>
>> I plan on removing Session#createFilter.  There are numerous reasons why
>> which I can discuss if anyone is interested in exploring this.
>>
>> Ultimately I think it makes sense to handle this via Java 8 streams[1]
>> although I am not sure that needs to happen in 6.0
>>
>> [1] https://hibernate.atlassian.net/browse/HHH-10962
>>
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>
>>


More information about the hibernate-dev mailing list