繁体   English   中英

休眠会创建错误的查询?

[英]hibernate creates wrong query?

嗨,我基本上有这个映射:

@Entity
@Table(schema="xas",name="billing")

public class Billing implements Serializable{

private String id;

private List<Subtotal> subtotals = new ArrayList<Subtotal>(3);

@Id
@Column(name = "id", nullable = false,length=32)
public String getId() {
    return id;
}

.....

public void addSubtotal(Subtotal subtotal) {
    subtotals.add(subtotal);
}

@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name="billing_id")
@IndexColumn(name="idx")
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public List<Subtotal> getSubtotals() {
    return subtotals;
}

public void setSubtotals(List<Subtotal> subtotals) {
    this.subtotals = subtotals;
}

}

当我查询帐单时:

Criteria criteria = session.createCriteria(Billing.class);
        criteria.add(Restrictions.in("id", ids));
        List<Billing> list = criteria.list();

我基本上得到此查询,它将检索我而不是一个帐单两个:

    select *
from oopfmobiles.billing this_ 
left outer join Subtotal subtotals2_ on this_.id=subtotals2_.billing_id 
where this_.id in ('an_id')

怎么了? 先感谢您。

ids变量的内容是什么? 您是否两次收到相同的Billing实例?

如果是这样,则必须确保使用DistinctRootEntityTransformer。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM