Home » Support » Forum » Criteria query error: Unexpected query token

Criteria query error: Unexpected query token


Using JPA2, I can save entities now in JBoss, and also fetch them uniquely by id. However, if I try to fetch it by getting back all instances (e.g. findAll, I get the following error:

org.jboss.arquillian.spi.ArquillianProxyException: com.objectdb.o._PersistenceException : Unexpected query token 'FROM' (SELECT is expected) [Proxied because : Could not find suitable constructor]
at com.objectdb.o._PersistenceException.b(_PersistenceException.java:45)
at com.objectdb.o.JPE.g(JPE.java:140)
at com.objectdb.o.ERR.f(ERR.java:59)
at com.objectdb.o.OBC.onObjectDBError(OBC.java:1398)



    public <T extends BaseEntity> List<T> findAll(Class<T> aClass) {
         CriteriaBuilder qb = entityManager.getCriteriaBuilder();
         CriteriaQuery<T> c = qb.createQuery(aClass);
         return entityManager.createQuery(c).getResultList();



@Table(name = "test_entity")
public class BaseEntityTest extends BaseEntity{

private static final long serialVersionUID = 613965399994067819L;

public BaseEntityTest() {

@Column(length = 16)
    private String testColumn;

    public String getTestColumn() {
        return testColumn;

    public void setTestColumn(String testColumn) {
        this.testColumn = testColumn;

public abstract class BaseEntity implements Serializable{

    private static final long serialVersionUID = -7979088681300801112L;
     * Primary key for entity
//    @GeneratedValue(strategy = GenerationType.TABLE, generator = "sequences")
//    @TableGenerator(name = "sequences", initialValue = 1, allocationSize = 50)
//    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Long id;

     * Version of object, supporting optimistic lock
    @Column (name = "opt_lock")
    private Long optimisticLock;

     * Flag to disable entity
    private boolean deleted = false;

     * Audit
    private Audit audit;

    public Long getId() {
        return id;

    public Long getOptimisticLock() {
        return optimisticLock;

The same code, against a PostgreSQL jta datasource works fine however. Is there anything glaringly wrong with my code I'm failing to see? Or is Criteria a W.I.P?




It seems that the query is invalid because a SELECT is not specified.

Unexpected query token 'FROM' (SELECT is expected)

A query with no SELECT may be valid in Hibernate HQL but not in JPQL and JPA Criteria API.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

My apologies, in my eagerness to test I think I need to do an audit on all criteria queries. Works well. Fetched 256,000 records in 9 seconds (laptop). Pretty good!!!!

If anyone is interested in my mistake, the fixed shared code is:

public <T extends BaseEntity> List<T> findAll(Class<T> aClass) {
     CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
     CriteriaQuery<T> q = criteriaBuilder.createQuery(aClass);
     Root<T> entityRoot = q.from(aClass);
     return entityManager.createQuery(q).getResultList();

Thanks again, I'm enjoying the simplicity of objectdb. Now I'm going to setup the JDO annotations to build up indexes.


Post Reply

To post a reply and/or subscribe to update notifications - please login