It works fine, but until hiber table aliases not used. And now im trying to pass Root as argument to my function (to get alias name). But im getting “InvalidDataAccessResourceUsageException: Error interpreting query [SqmRoot not yet resolved to TableGroup]”
As i understood, the problem is that FromClauseIndex does not contain alias for SqmRoot (sqmRoot has).
Have you any ideas about it? Where i can find info about Sqm root resolution process?
I don’t know what you think you’re doing there, but using the physical order of rows for pagination is a very bad idea, because the physical order can change between transactions.
If you really must use this, I would at least urge you to avoid this complicated bit transformation, because the tid data type is sortable. You can just use this:
functionRegistry.registerPattern(
"get_ctid",
new AbstractSqmSelfRenderingFunctionDescriptor( "get_ctid", StandardArgumentsValidators.exactly( 1 ), StandardFunctionReturnTypeResolvers.invariant( basicTypeRegistry.resolve( StandardBasicTypes.STRING ) ), null ) {
@Override
public void render(
SqlAppender sqlAppender,
List<? extends SqlAstNode> arguments,
ReturnableType<?> returnType,
SqlAstTranslator<?> walker) {
final SqlAstNode sqlAstNode = arguments.get(0);
final ColumnReference reference;
if ( sqlAstNode instanceof Assignable ) {
final Assignable assignable = (Assignable) sqlAstNode;
reference = assignable.getColumnReferences().get(0);
}
else if ( sqlAstNode instanceof Expression ) {
final Expression expression = (Expression) sqlAstNode;
reference = expression.getColumnReference();
}
else {
throw new HqlInterpretationException( "path did not map to a column" );
}
sqlAppender.appendSql( reference.getQualifier() );
sqlAppender.appendSql( ".ctid" );
}
}
);