Question

Is it thread-safe to use QueryDsl query entities like the following

public class MyDaoImpl implements MyDao {

    private static final QEntity entity = QEntity.entity;

    public List<Entity> entities() {
        return new JPAQuery(em).from(entity).list(entity);
    }

    public List<Entity> otherEntities() {
        return new JPAQuery(em).from(entity).where(entity.foo.isNull()).list(entity);
    }
}

As opposed to:

public class MyDaoImpl implements MyDao {

    public List<Entity> entities() {
        QEntity entity = QEntity.entity;
        return new JPAQuery(em).from(entity).list(entity);
    }

    public List<Entity> otherEntities() {
        QEntity entity = QEntity.entity;
        return new JPAQuery(em).from(entity).where(entity.foo.isNull()).list(entity);
    }
}
Was it helpful?

Solution

Found the answer from this Google Groups discussion

In short,

  1. QueryDsl expressions are thread-safe
  2. QueryDsl queries are not
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top