HibernateQueryTranslator extends
        AbstractHibernateQueryTranslator<Criterion, Orders, Projection> implements QueryTranslator<Criterion, Orders, Projection> { @Override protected <T> Criterion translate(NativeExpression e, Class<T> entityClass) { Class<?> expressionClass = e.getExpressionClass(); if (expressionClass == String.class) { return Restrictions.sqlRestriction("(" + e.getExpression().toString() + ")"); } else if (Criterion.class.isAssignableFrom(expressionClass)) { return (Criterion) e.getExpression(); } else { throw unsupported(e); } } HibernateQueryTranslator(HibernatePropertyResolver propertyResolver,
            BoxMaker boxMaker,
            ContainsExpressionHandler<Criterion> containsExpressionHandler);  HibernateQueryTranslator(HibernatePropertyResolver propertyResolver,
            BoxMaker boxMaker);  HibernateQueryTranslator(HibernatePropertyResolver propertyResolver); @Override Criterion eq(String fieldName, Object value); @Override Criterion ne(String fieldName, Object value); @Override Criterion lt(String fieldName, Object value); @Override Criterion lte(String fieldName, Object value); @Override Criterion gt(String fieldName, Object value); @Override Criterion gte(String fieldName, Object value); @Override Criterion between(String fieldName, Object from, Object to); @Override Criterion in(String fieldName, Object[] values); @Override Criterion notIn(String fieldName, Object[] values); @Override Criterion isNull(String fieldName); @Override Criterion notNull(String fieldName); @Override Criterion isEmpty(String fieldName); @Override Criterion notEmpty(String fieldName); @Override Criterion within(
            String xFieldName, String yFieldName, Box<N> box); @Override Criterion and(Criterion... subqueries); @Override Criterion or(Criterion... subqueries); @Override Orders order(String fieldName, Ordering.Order o); @Override Orders order(Orders... orders); @Override Projection translateProjection(Query<T, R> query);  }
@Test public void translate_NativeExpression_String() { String query = "some SQL query"; NativeExpression e = new NativeExpression(String.class, query); Criterion expected = Restrictions.sqlRestriction("(" + query + ")"); Criterion actual = translator.translate(e, Void.class); assertEquals(expected.toString(), actual.toString()); assertEquivalent(expected, actual); }
@Test(expected = UnsupportedOperationException.class) public void translate_NativeExpression_unsupported() { Integer query = 1; NativeExpression e = new NativeExpression(Integer.class, query); translator.translate(e, Void.class); }