开发者

hibernate creates wrong query?

Hi I have basically this mapping:

@En开发者_Python百科tity
@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;
}

}

And when I query billing:

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

I get basically this query which will retrieve me instead one billing two:

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

What's wrong? Thank you in advance.


What is the content of the ids variable ? Do you receive the same Billing instance twice ?

If so, you'll have to make sure that you use the DistinctRootEntityTransformer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜