Ho un mapping @ManyToMany in cui la tabella fa riferimento a una tabella di mappatura e vogliamo ordinare su un ID ordine nella tabella di mappatura effettiva, ma trovo difficile configurarlo .Ordinamento in base al valore della tabella di mappatura in Hibernate
Possiamo eseguirlo in hibernate xml, quindi è naturale supporre che il supporto sia presente nelle annotazioni JPA. Qualcuno sa come possiamo ordinare un valore nella tabella di mappatura?
La tabella è:
wap_site_components
intid
strname
intcomponentdef
dtmcreated
intcustomer
e la tabella di mapping che l'auto-riferimenti è:
wap_site_component_relations
intid
intparent (references intid in wap_site_components)
intchild (references intid in wap_site_components)
intorder (this is the value we want to order the collection on)
In Hibernate Annotazioni abbiamo:
@ManyToMany (fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable (name = "wap_site_component_relations",
joinColumns = {@JoinColumn (name = "intparent", referencedColumnName = "id") },
inverseJoinColumns = {@JoinColumn (name = "intchild", referencedColumnName = "id") })
public Set<WapComponent> getChildren() {
return children;
}
Questo è il modo ci siamo esibiti in hibernate xml:
<set
name="children"
table="wap_site_component_relations"
lazy="true"
cascade="none"
sort="unsorted"
order-by="intorder"
mutable="false"
>
<cache
usage="read-only"
/>
<key
column="intparent"
>
</key>
<many-to-many
class="se.plusfoursix.im46.data.wap.WapComponent"
column="intchild"
outer-join="auto"
/>
</set>
Quindi vogliamo utilizzare il tag @OrderBy ma non possiamo fare riferimento al valore intorder nella tabella di mapping. Qualche idea? Grazie.
(abbiamo cercato un @OrderBy (intorder) sulla raccolta dei bambini nel codice, ma che non ha funzionato per noi)
Vorrei anche aggiungere che potremmo fare questo facendo la tabella di mappatura un fagiolo, ma preferirei non farlo. – bowsie