5

使用 QueryDsl 查询实体是否是线程安全的,如下所示

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);
    }
}

相对于:

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);
    }
}
4

1 回答 1

7

从这个 Google Groups 讨论中找到答案

简而言之,

  1. QueryDsl 表达式是线程安全的
  2. QueryDsl 查询不是
于 2013-09-06T11:28:57.547 回答