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);
    }
}
Était-ce utile?

La solution

Found the answer from this Google Groups discussion

In short,

  1. QueryDsl expressions are thread-safe
  2. QueryDsl queries are not
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top