0

Hi I have basically this mapping:

@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;
}

}

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.

1 Answer 1

0

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.

1
  • yes exactly, it can be what so ever, if there is only one id I got 2rows. if there are two ids I got 4rows instead of 2. And it's (List<String>). I guess problem is with subtotals mapping.
    – feiroox
    Sep 7, 2010 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.