persistence@glassfish.java.net

RE: WG: mappedBy problem in subclasses

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Tue, 22 May 2007 14:51:27 +0100

Hi,

The relationship in your classes need to be set properly.

Reference them well. Like for example below:

Entity class Iteamdetailsent has a relationships with entity class
Departmentent. Iteamdetailsent sets the relationship with Department as
private Departmentent departmentent; and it is maped properly as
(mappedBy="departmentent") in Departmentent. See below:


Iteamdetailsent
@ManyToOne()
        @JoinColumn(name="DeptID")
        private Departmentent departmentent;


Departmentent

@OneToMany(mappedBy="departmentent")
        private Collection <Iteamdetailsent> iteamdetailsent;

Thanks

eve


>From: <Juerg.Treichler_at_gs-vbs.admin.ch>
>Reply-To: persistence_at_glassfish.dev.java.net
>To: <persistence_at_glassfish.dev.java.net>
>Subject: WG: mappedBy problem in subclasses
>Date: Tue, 22 May 2007 14:26:22 +0200
>
>
>
> > I created three entity classes:
> >
> > An abstract class Type
> > @Entity
> > public abstract class Type implements Serializable {
> > private static final long serialVersionUID = 1L;
> > private Long id;
> > private java.sql.Timestamp Version;
> >
> > public Type() {
> > }
> >
> > public void setId(Long id) {
> > this.id = id;
> > }
> >
> > @Id
> > @GeneratedValue(strategy = GenerationType.AUTO)
> > public Long getId() {
> > return id;
> > }
> >
> > @Version
> > public Timestamp getVersion() {
> > return Version;
> > }
> >
> > public void setVersion(Timestamp Version) {
> > this.Version = Version;
> > }
> >
> >
> > }
> >
> > A subclass "ClassDef"
> >
> > @Entity
> > public class ClassDef extends Type implements Serializable {
> > private static final long serialVersionUID = 1L;
> > private String Name;
> > private boolean Abstract;
> > java.util.List<Attribute> Attributes;
> >
> > public ClassDef() {
> > Attributes = new java.util.ArrayList<Attribute>();
> >
> >
> > }
> >
> > @Column(nullable=false)
> > public String getName() {
> > return Name;
> > }
> >
> > public void setName(String Name) {
> > this.Name = Name;
> > }
> >
> > public boolean isAbstract() {
> > return Abstract;
> > }
> >
> > public void setAbstract(boolean Abstract) {
> > this.Abstract = Abstract;
> > }
> >
> >
> >
>@OneToMany(cascade=javax.persistence.CascadeType.ALL,mappedBy="ClassOwner")
> > public List<Attribute> getAttributes() {
> > return Attributes;
> > }
> >
> > public void setAttributes(List<Attribute> Attributes) {
> > this.Attributes = Attributes;
> > }
> >
> > public void addAttribute(Attribute a) {
> > Attributes.add(a);
> > a.setClassOwner(this);
> > }
> >
> > public Attribute newAttribute() {
> > Attribute a = new Attribute();
> > this.addAttribute(a);
> > return a;
> > }
> >
> > public Attribute getAttribute(long iID) {
> > for (Attribute a:this.getAttributes()) {
> > if (a.getId() == iID)
> > return a;
> > }
> > return null;
> > }
> >
> > public void removeAttribute(Attribute a) {
> > Attributes.remove(a);
> > a.setClassOwner(null);
> > }
> >
> > }
> >
> > And a third class "Attribute".
> >
> > @Entity
> > public class Attribute implements Serializable {
> > private static final long serialVersionUID = 1L;
> > private Long id;
> > private String Name;
> > private ClassDef ClassOwner;
> > private Type Type;
> >
> >
> > public Attribute() {
> > }
> >
> > public void setId(Long id) {
> > this.id = id;
> > }
> >
> > @Id
> > @GeneratedValue(strategy = GenerationType.AUTO)
> > public Long getId() {
> > return id;
> > }
> >
> > @Column(nullable=false)
> > public String getName() {
> > return Name;
> > }
> >
> > public void setName(String Name) {
> > this.Name = Name;
> > }
> >
> > @ManyToOne()
> > @JoinColumn(nullable=false)
> > public ClassDef getClassOwner() {
> > return ClassOwner;
> > }
> >
> > public void setClassOwner(ClassDef ClassOwner) {
> > this.ClassOwner = ClassOwner;
> > }
> >
> > @ManyToOne
> > public Type getType() {
> > return Type;
> > }
> >
> > public void setType(Type Type) {
> > if (Type == this.getClassOwner()) {
> > //TODO Exception if an attribute is of the same type as his owner
> > return;
> > }
> > this.Type = Type;
> > }
> >
> >
> >
> > }
> >
> > The error message i get is:
> >
> > Internal Exception: Exception [TOPLINK-7154] (Oracle TopLink Essentials
>- 2.0 (Build b47-beta3 (05/16/2007))):
>oracle.toplink.essentials.exceptions.ValidationException
> > Exception Description: The attribute [attributes] in entity class [class
>org.JTSoft.POEM.BaseLib.ClassDef] has a mappedBy value of [ClassOwner]
>which does not exist in its owning entity class [class
>org.JTSoft.POEM.BaseLib.Attribute]. If the owning entity class is a
>@MappedSuperclass, this is invalid, and your attribute should reference the
>correct subclass.
> > at
>oracle.toplink.essentials.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:229)>
> >
> > I can't fix the problem. Where is the missing part of the puzzle?
> >
> > Kind regards
> >
> > Jürg
> >
> >
> >
>-----------------------------------------------------------------------------------------------
> > dipl. Informatik-Ing. ETH Jürg Treichler
> > IT-Architekt
> >
> > Eidgenössisches Departement für Verteidigung,
> > Bevölkerungsschutz und Sport VBS
> > Generalsekretariat VBS
> > Informatik VBS
> > Maulbeerstrasse 9; 3003 Bern
> > +41 (31) 324 73 42 (Tel.)
> > +41 (31) 324 88 99 (Fax)
> > juerg.treichler_at_gs-vbs.admin.ch
> > www.vbs.admin.ch
> >
>-----------------------------------------------------------------------------------------------
> >
>

_________________________________________________________________
Could you be the guest MSN Movies presenter? Click Here to Audition
http://www.lightscameraaudition.co.uk