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