The substring example code is in the documentation:
List<String> prefixes = entityManager.createQuery(
"select substring( p.number, 0, 2 ) " +
"from Call c " +
"join c.phone p", String.class )
.getResultList();
However this example is slightly confusing in that it implies that start position is 0-based, while both SQL and JPA 2.1 (section 4.6.17.2.1) make clear it should be 1-based. The example code should be updated to use start position 1, and the documentation should explicitly mention that it is 1-based. |