0
Salut J'ai essentiellement ce mapping:hibernate crée une mauvaise requête?
@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;
}
}
Et quand je fais une recherche de facturation:
Criteria criteria = session.createCriteria(Billing.class);
criteria.add(Restrictions.in("id", ids));
List<Billing> list = criteria.list();
je reçois essentiellement cette requête qui me récupérer à la place une facturation deux:
select *
from oopfmobiles.billing this_
left outer join Subtotal subtotals2_ on this_.id=subtotals2_.billing_id
where this_.id in ('an_id')
Qu'est-ce qui ne va pas? Merci d'avance.
oui exactement, il peut être ce que jamais, s'il n'y a qu'un seul ID j'ai 2rows. s'il y a deux identifiants j'ai 4rows au lieu de 2. Et c'est (Liste). Je suppose que le problème est avec la cartographie des sous-totaux. –
feiroox
Le transformateur DISTINCT_ROOT_ENTITY a beaucoup aidé – feiroox