Usages of {{ResultTransformer}} were deprecated in 5.2. For 6.0 let's develop the better way to apply this idea, splitting this into 2 distinct functional contracts: {{TupleTransformer}} and {{ResultListTransformer}}.
There is some uncertainty we need to clarify with regards to how TupleTransformer and RowTransformer play together when the query is "typed".
The "highest level" of transformation is the type defined for a TypedQuery which defines the type of the individual "rows" returned by the Query to the user. This resultType may be: # {{Object[].class}} to indicate that an Object[] should be the row type (so-called "pass thru" transformer). # Tuple.class which indicates that the results should be wrapped in a JPA Tuple # Some other value which indicates the expected row type. This is limited to cases where either: ## the query defined a single "select expression" and the resultType names the type of that selection ## the user supplied a {{TupleTransformer}} and the resultType names that {{TupleTransformer}} return type.
For example: {code} // case 1 - implicit session.createQuery( "select a.name, a.dateOfBirth, a.sex from Animal" )...
// case 1 - explicit session.createQuery( "select a.name, a.dateOfBirth, a.sex from Animal", Object[].class )...
// case 2 (a) session.createQuery( "select a.name, a.dateOfBirth, a.sex from Animal", Tuple.class )...
// case 2 (b) session.createQuery( "select a.name as name, a.dateOfBirth as dob, a.sex as sex from Animal", Tuple.class )...
// case of 3.1 session.createQuery( "select a.name from Animal", String.class )...
// case of 3.2 session.createQuery( "select a.name, a.dateOfBirth, a.sex from Animal", DTO.class ) .setTupleTransformer( new TupleTransformer<DTO>() {...} )... {code}
Some that we specifically need to decide on: {code} // IMO either: // 1) this is invalid, or // 2) the Tuple construction needs to be the last applied - and we have a problem wrt who gets to "consume" // the aliases : the Tuple or the TupleTransformer? The end result in that case would be a List of Tuples whose // only value would be the DTO. session.createQuery( "select a.name as name, a.dateOfBirth as dob, a.sex as sex from Animal", Tuple.class ) .setTupleTransformer( new TupleTransformer<DTO>() {...} )...
// we could allow this too - essentially our TupleTransformer is creating the JPA Tuple in some custom way // although I am not a fan of checking the type parameters to know the difference between this and the // case above; perhaps a "special" contract like `interface TupleBuilder extends TupleTransformer ` to indicate // that we are building the Tuple session.createQuery( "select a.name as name, a.dateOfBirth as dob, a.sex as sex from Animal", Tuple.class ) .setTupleTransformer( new TupleTransformer<Tuple>() {...} )... {code} |
|