2

I have a table in which certain words or word groups are stored. I want to select entries which start with an uppercase letter, cointain no space and contain only letters. My SQL looks like this:

select word from words where w_id > 100 AND word REGEXP '^[A-Z][A-Za-z]*$' limit 2000;

How do I do the same thing using criteria?

user1406177
  • 1,328
  • 2
  • 22
  • 36

1 Answers1

4

Try this:

List words = session.createCriteria(Word.class)
.setProjection(Projections.property("word"))
.add(Restrictions.and(Restrictions.gt("w_id",100), Restrictions.sqlRestriction(word REGEXP '^[A-Z][A-Za-z]*$')))
.setMaxResults(2000).list();
AstroCB
  • 12,337
  • 20
  • 57
  • 73
user3487063
  • 3,672
  • 1
  • 17
  • 24