将QueryDsl查询实体用作dao字段是否是线程安全的

时间:2013-09-06 11:19:06

标签: thread-safety querydsl

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

1 个答案:

答案 0 :(得分:6)

this Google Groups discussion

找到答案

简而言之,

  1. QueryDsl表达式是线程安全的
  2. QueryDsl查询不是