Question

I'm trying to select a substring of column, i.e. select substring(description, 1, 200) from category where id=1

Is it possible to have a substring function within a select statement in JPQL/JPA 2? If yes, how? If no, are there any alternatives? Thanks.

Was it helpful?

Solution

There is a scalar expression for this: SUBSTRING(string, start, end)

I believe this is allowed in the SELECT clause in JPA 2.0, but not in JPA 1.0.

OTHER TIPS

I'm afraid there is not such function yet. There is a substring function but can only be used in the WHERE part of your query.

Your most simple alternative would be to invoke the String class substring method for each row.

Hope this helps!

Regards,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top