【问题标题】:Is it thread-safe to use QueryDsl query entities as dao fields使用 QueryDsl 查询实体作为 dao 字段是否是线程安全的
【发布时间】:2013-09-06 11:19:06
【问题描述】:

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

【问题讨论】:

    标签: thread-safety querydsl


    【解决方案1】:

    this Google Groups discussion找到答案

    总之,

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

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2011-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      相关资源
      最近更新 更多