[英]Hibernate OneToMany with OrderBy generates invalid SQL
I have a one-to-many relationship as follows: 我的一对多关系如下:
public class Player {
private int id;
private String name;
private List<Payment> payments;
... accessors etc
}
public class Payment {
private int id;
private Date when;
private BigDecimal amount;
... accessors etc
}
orm to describe these: orm描述这些:
<entity-mappings ... version="2.0">
<entity class="domain.Player" access="FIELD">
<attributes>
<id name="id">
<generated-value strategy="AUTO" />
</id>
<basic name="name" optional="false" />
<one-to-many name="payments" fetch="EAGER">
<order-by>when</order-by>
<cascade><cascade-all/></cascade>
</one-to-many>
</attributes>
</entity>
<entity class="domain.Payment" access="FIELD">
<attributes>
<id name="id">
<generated-value strategy="AUTO" />
</id>
<basic name="when" optional="false" />
<basic name="amount" optional="false" />
</attributes>
</entity>
</entity-mappings>
This works fine with Hibernate 4.2.2.Final, but if I update to 4.3.4.Final it fails whenever I try to load objects of type player. 这在Hibernate 4.2.2.Final上可以正常工作,但是如果我更新到4.3.4.Final,则每次尝试加载Player类型的对象时都会失败。 The SQL generated by 4.3.4.Final is along the lines of :
4.3.4.Final生成的SQL遵循以下原则:
select ...
from Player player0_
left outer join Player_Payment payments1_ on player0_.id=payments1_.Player_id
left outer join Payment payment2_ on payments1_.payments_id=payment2_.id
where player0_.id=?
order by payments1_.when
ie the ORDER BY is on the join table, not the target table. 即ORDER BY在联接表上,而不在目标表上。
Any ideas - am I doing something wrong here or does this look like a Hibernate bug ? 任何想法-我在这里做错了还是看起来像是Hibernate错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.