Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it thread-safe to use QueryDsl query entities as dao fields

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);
    }
}
like image 799
RJo Avatar asked Sep 06 '13 11:09

RJo


1 Answers

Found the answer from this Google Groups discussion

In short,

  1. QueryDsl expressions are thread-safe
  2. QueryDsl queries are not
like image 93
RJo Avatar answered Jan 01 '23 11:01

RJo