使用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);
}
}
最佳答案
找到了this Google Groups discussion的答案
简而言之,
关于thread-safety - 将QueryDsl查询实体用作dao字段是否具有线程安全性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18656563/