persistence@glassfish.java.net

Re: WG: mappedBy problem in subclasses

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

Hi,

Also could you have a look at this variable:

'private static final long serialVersionUID = 1L;'

an entity should not have any final variable or methods.
Please double check this as I maybe wrong.

eve


>From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
>Reply-To: persistence_at_glassfish.dev.java.net
>To: persistence_at_glassfish.dev.java.net
>Subject: Re: WG: mappedBy problem in subclasses
>Date: Tue, 22 May 2007 14:46:20 +0200
>
>Hi Jürg,
>
>your classes use property based access type, meaning the persistent state
>is defined using JavaBeans style property accessors. The getter/setter
>methods
> public ClassDef getClassOwner()
> public void setClassOwner(ClassDef ClassOwner)
>define a property called classOwner. Please note the property name starts
>with a lower case 'c'.
>
>I propose you try to use the lower case property name in your mappedBy
>clause:
>
>@OneToMany(cascade=javax.persistence.CascadeType.ALL,mappedBy="classOwner")
>
>Regards Michael
>
>>
>>
>>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_ <mailto:juerg.treichler_at_gs-vbs.admin.ch>
>>_www.vbs.admin.ch_ <file://www.vbs.admin.ch>
>>-----------------------------------------------------------------------------------------------
>>
>>

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