mysql—选择实体包含列表的位置,其中元素包含另一个列表

i86rm4rw  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(518)

我正在springjpa中编写一个jpql查询,我有以下场景。我有一个实体margin,它包含perperperiodmargin的列表,perperperiodmargin的每个元素都包含marginfactor的列表。代码:

@Entity
public class Margin {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  @OneToMany(mappedBy = "margin", cascade = CascadeType.ALL, orphanRemoval = true)
  private List<PerPeriodMargin> perPeriodMargins;
}

@Entity
public class PerPeriodMargin{
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  @ManyToOne
  private Margin margin;
  @OneToMany(mappedBy = "perPeriodMargin", cascade = CascadeType.ALL, orphanRemoval = true)
  private List<MarginFactor> marginFactors;
}

@Entity
public class MarginFactor{

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  @ManyToOne
  private Underlying underlying;
  @ManyToOne
  private PerPeriodMargin perPeriodMargin;
}

我想选择在单个jpql查询中作为参数传递marginfactor underlined.id的所有边距?有什么建议吗?
我通过application.properties“logging.level.org.hibernate.sql=debug”中的这一行激活了hibernate日志记录,我对生成的sql查询感到困惑。似乎多重连接有问题。谁能解释一下吗。
选择*from margin m inner join per\u period\u margin ppm on m.id=ppm.margin\u id join margin\u factor mf on ppm.id=mf.per\u period\u margin\u id,其中mf.underlying\u id=?m.id=(从交易账户ta中选择保证金,其中ta.id=?)
再加上保证金
选择PerPerPerPeriodim0\u。选择PerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerM0。选择PerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerPerU id=?
到目前为止一切都很好。
最后还有另外两个查询试图获取marginfactors。
选择marginfact0\u0.per\u period\u margin\uID as peri6\u 9\u 0\u0,marginfact0\uID as id1\u 9\u 0\u0,marginfact0\uID as id1\u 9\u 1\u0,marginfact0\u0.bid as Bidd 2\u 9\u 1\u0,marginfact0\u0.ConceptualAs Conceptual3\u 9\u 1\u0,marginfact0\u0.offer4\u 9\u 1\u0,marginfact0\u0.period\u marginfact0\uID as settleme5\u 9\u 1\u0,marginfact0\u0.underlyu id as underlyi7\u 9\u 1\u,underlying1\u1.id as id1\u 24\u 2\u,underlying1\u数字as digits2\u 24\u 2\u,underlying1\u显示为3\u 24\u 2\u,underlying1\u启用为enable4\u 24\u 2\u,underlying1\u。enable\u buy as enable\u b5\u 24\u 2\u,underlying1\u。enable\u sell as enable\u s6\u 24\u 2\u,underlying1\u。focus\u数字as focus\u di7\u 24\u 2\u,underlying1\ focus\ position as focus\ po8\ u 24\ u 2\ underlying1\ left\ u currency\ u id as left\ u 11\ u 24\ u 2\ underlying1\ name as name9\ u 24\ u 2\ underlying1\ right\ u currency\ u id as right\ u c12\ u 24\ u 2\ underlying1\ temporary\ u disable as tempora10\ u 24\ u 2\ currency2\ id as id1\ u 3\ u,currency2\数字as digits2\ u 3\ u,currency2\ enable\ buy as enable\ u b3\ u 3\ u,现金流2\currency2。enable\U Sel售售售售为enable Ou S 4\u 3\u 3\u 3,currency2。名称名称为name5\u 3\u 3 3\u 3,currency2,currency2。符号为symbol6\u 3\u 3,currency2。符号为symbol6\u 3\u 3\u 3。enable\U卖售为enable卖售为enable。临时性卖售为临时性禁用作为临时性8\u 3\u 3,Currenc2。临时性售为临时性禁用作为临时性禁用作为临时性3\u 3\u 3,临时性禁用作为临时性禁用作为临时性禁用,Currenc3。临时性禁用作为临时性禁用作为临时性禁用,Currenc3。id。id。id id id作为id作为id作为id作为id作为id作为id作为id作为id作为id作为id1\u 3\u 3\u 3\u 3\十一、,货币符号为symbol6\U 3\U 4\,currency3\u0.temporary\u disable as temporar7\u 3\u 4\from margin\u factor marginfact0\u0左外部联接基础货币1\u0上的基础货币1\u0。基础货币id=基础货币1\uid。左外部联接货币2\u2\u2\uid=货币2\uid。左外部联接货币3\u3\u1\u1上的基础货币1\uid=货币3\u3.id,其中保证金0。每期保证金id=?
正如我们在上一个查询中看到的,perperperiodmarginid上只有一个where条件。我认为它还必须包含基础条件,因为这个查询负责获取marginfactors,我们必须从中提取具有特定underlyingid的数据。
我真的很认真这个问题,请有人解释一下,或者这是一个错误在冬眠!

n3ipq98p

n3ipq98p1#

以下是查询:

select m 
FROM Margin m 
JOIN m.perPeriodMargins ppm 
JOIN ppm.marginFactors mf 
JOIN mf.underlying und 
WHERE und.id = :id

相关问题