| To be more precise... The problem I was referring to is that, currently, setProjection mutates the FullTextQuery, making the type returned by a given FullTextQuery change at runtime. For instance:
FullTextQuery<Foo> query = session.createFullTextQuery( query, Foo.class ); query.setProjection( "someField" ); List<Foo> results = query.list();
I agree there is a user mistake in this code, but the purpose of typing is precisely to avoid that kind of mistake, so we're not really making our API better here. As discussed on HipChat, we could avoid this issue by removing setProjection and replacing it with a non-mutating method that would return a new instance, let's say ".withProjection":
FullTextQuery<Foo> query = session.createFullTextQuery( query, Foo.class ); query.withProjection( "someField" ); List<Foo> results = query.list();
Which would then be, with correct code:
FullTextQuery<Foo> query = session.createFullTextQuery( query, Foo.class );
FullTextQuery<Object[]> projectedQuery = query.withProjection( "someField" );
List<Object[]> results = projectedQuery.list();
Assuming setResultTransformer (which has the exact same problem) was fixed the same way (by making ResultTransformer generic), we'd still have an issue:
ResultTransformer<T> myTransformer = ... ;
session.createFullTextQuery( query, Foo.class )
.withProjection( "someField" )
.withResultTransformer( myTransformer );
session.createFullTextQuery( query, Foo.class )
.withResultTransformer( myTransformer )
.withProjection( "someField" );
Also, we'd have yet another issue with the behavior described in
HSEARCH-2225 Open (see the comments there). So... Yes, I think we'll need to think about it  |