You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by it...@daimler.com on 2009/01/19 11:20:13 UTC
@OneToMany/@ManyToOne Weirdness (List contains non-matching elements)
Hello Everybody,
I'm having some weird issues with a simple OneToMany/ManyToOne Situation.
The data model is as follows:
@Entity
@Table(name = "REFERENZCODES")
public class ReferenzCode
{
@Id
@Column(name = "RFC_CODE")
private String code;
@Column(name = "RFC_BEZEICHNUNG")
private String bezeichnung;
@Column(name = "RFC_PFLEGE_KZ")
private String pflegeKennzeichen;
@Column(name = "RFC_USER_ID")
private String userId;
@Column(name = "RFC_DATUM")
private Date aenderungsDatum;
@Version
@Column(name = "RFC_VERSION")
private long version;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST,
mappedBy="parent")
private List<ReferenzWert> referenzWerte;
@Entity
@Table(name = "REFERENZWERTE")
public static class ReferenzWert
{
@Id
@Column(name = "RFW_CODE")
private String code;
@Column(name = "RFW_RFC_CODE")
private String referenzCode;
@Column(name = "RFW_SUBRFC_CODE")
private String subCode;
@Column(name = "RFW_TEXT")
private String text;
@Column(name = "RFW_WERT")
private long wert;
@Column(name = "RFW_ALTERNATIV_TEXT")
private String alternativText;
@Column(name = "RFW_ALTERNATIV_WERT")
private long alternativWert;
@Column(name = "RFW_DATUM")
private Date aenderungsDatum;
@Column(name = "RFW_USER_ID")
private String userId;
@Version
@Column(name = "RFW_VERSION")
private long version;
@ManyToOne
@JoinColumn(name="RFW_RFC_CODE")
private ReferenzCode parent;
}
}
While the @ManyToOne is completely correct, the @OneToMany contains for a
RFC_CODE/RFW_RFC_CODE = "SPARTE" elements in the List that do NOT belong
to this leading to the following situation
ReferenCode (SPARTE)
-> referenWerte
0 -> ReferenzWert (5) with parent ReferenzCode
(SPARTE)
1 -> ReferenzWert (8) with parent ReferenzCode
(<somethingElse>)
I do not really understand what happends here. All ReferenzWerte of
ReferenzCode SPARTE are present, BUT there are some additional ones that
do not belong
here.
Any help with this issue would be appreciated. I'm using Websphere 6.1
(FeaturePack EJB3 with openJPA 1.0.3). If I do a manual query for all
ReferenzWerte to
a certain ReferenzCode via NamedQuery, everything works as expected.
Thanks in advance,
Heiko
--
Dr.-Ing. Heiko Kopp / Fa. GFI - iT media Consult GmbH
c/o Mercedes-Benz Bank
HPC 032 - ITF/FS-DPS
70469 Stuttgart
Tel.: 0711 2574-6144
Fax: 0711 2574-96144
E-Mail: it-media.kopp@daimler.com
If you are not the intended addressee, please inform us immediately that you have received this e-mail in error, and delete it. We thank you for your cooperation.
Re: @OneToMany/@ManyToOne Weirdness (List contains non-matching
elements)
Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
The way RFW_RFC_CODE column is used at following two different context, it
leaves open a possibility of coding error.
@ManyToOne
@JoinColumn(name="RFW_RFC_CODE")
private ReferenzCode parent;
@Column(name = "RFW_RFC_CODE")
private String referenzCode;
For example,
ReferenzCode p = new ReferenzCode();
ReferenzWert c = new ReferenzWert();
p.code = "X";
p.referenzWerte.add(c);
c.parent = p;
c.referenzCode = "Y"
What is the expected value in the column REFERENZWERTE.RFW_RFC_CODE?
I will advise to remove the following declaration altogether
@Column(name = "RFW_RFC_CODE")
private String referenzCode;
--
View this message in context: http://n2.nabble.com/%40OneToMany-%40ManyToOne-Weirdness-%28List-contains-non-matching-elements%29-tp2180688p2237293.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.