We had a discussion regarding setResultTransformer with Steve Ebersole, and basically what's wrong in my previous comment is that the type parameter T in Query<T> is set from the start and cannot change, even if you call setResultTransformer. Basically there is a constraint on setResultTransformer that only allows to use a ResultTransformer<T>, and T is the output type for the ResultTransformer, which will always get passed an Object[] as input. Also, it won't be setResultTransformer but setTupleTransformer or something like that, but it's another matter. Anyway... in our case, here are the solutions we could implement:
- to only ever use FullTextQuery<Object> as our return type
- or (it makes more sense) to make FullTextQuery not generic, extending Query<Object>
- or to use the "with" kind of method mentioned above, which would not change the query's return type but return a new query with a different return type (downside: users might expect additional changes to the original query to affect the new one).
- or to make users give us information about whether they want to project or not from the beginning. We would have two different ways to retrieve the query: FullTextQuery<Object[]> query = session.createFullTextProjectionQuery(Foo.class, Bar.class).projection("fooField", "barField") or FullTextQuery<FooBarCommonParentType> query = session.createFullTextQuery(Foo.class, Bar.class).
|