You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Fr...@alcatel.fr on 2002/11/29 12:34:58 UTC

1->n association

Hello, does anyone have a working example of 1->n association?
Let's say I have a A class that holds several reference of B objects.
Thus I have A->*B

In my java source code I got:
A {
  int id;
  Vector listOfB = new Vector();

  public void addB(B BObject) {
    listOfB.add(BObject);
  }

  getter and setter methods...

}


B {
  int id;
  int AId;

 getter and setter methods...
}


in my reference_user.xml file I have :
<class-descriptor name="A" table="TABLE_A">
  <field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
  <collection-descriptor name="listOfB" element-class-ref="B">
  <inverse-foreignkey field-id-ref="2"/>
  <collection-descriptor/>
<class-descriptor/>

<class-descriptor name="B" table="TABLE_B">
  <field-descriptor id="1" name="id"  column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
  <field-descriptor id="2" name="AId" column="A_ID"
jdbc-type="INTEGER"/>
</class-descriptor>


When executing, I get exceptions :
Error in operation [set] of object [PersistentFieldPropertyImpl],
java.lang.IllegalAccessException
Declaring class [B]
Property Name [AId]
Property Type [int]
anObject was class [B]
aValue was class [java.lang.Integer]

Can anyone help, please? I just want a working java source code with the
repository_user.xml.

Thanks


RE: 1->n association

Posted by Jorge Martins <Jo...@inesc-id.pt>.
Could it be that the getter/setter in class B for attribute AId is
get/setAId()?
I believe the correct name for the attribute in the mappings file would
be 'aId' instead of 'AId'...

Please correct me if I'm wrong... but this kind of error has been
appearing to me when there is no setter for a mapped attribute

Jorge

 
________________________________________________________________________
   inesc-id   Jorge Martins              | Jorge.B.Martins@inesc-id.pt
lisboa        Software Engineering Group |
http://www.esw.inesc-id.pt/~jorge



-----Original Message-----
From: Franck.Tran@alcatel.fr [mailto:Franck.Tran@alcatel.fr] 
Sent: sexta-feira, 29 de Novembro de 2002 11:35
To: ojb-user@jakarta.apache.org
Subject: 1->n association


Hello, does anyone have a working example of 1->n association? Let's say
I have a A class that holds several reference of B objects. Thus I have
A->*B

In my java source code I got:
A {
  int id;
  Vector listOfB = new Vector();

  public void addB(B BObject) {
    listOfB.add(BObject);
  }

  getter and setter methods...

}


B {
  int id;
  int AId;

 getter and setter methods...
}


in my reference_user.xml file I have :
<class-descriptor name="A" table="TABLE_A">
  <field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
  <collection-descriptor name="listOfB" element-class-ref="B">
  <inverse-foreignkey field-id-ref="2"/>
  <collection-descriptor/>
<class-descriptor/>

<class-descriptor name="B" table="TABLE_B">
  <field-descriptor id="1" name="id"  column="ID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
  <field-descriptor id="2" name="AId" column="A_ID"
jdbc-type="INTEGER"/> </class-descriptor>


When executing, I get exceptions :
Error in operation [set] of object [PersistentFieldPropertyImpl],
java.lang.IllegalAccessException Declaring class [B] Property Name [AId]
Property Type [int] anObject was class [B] aValue was class
[java.lang.Integer]

Can anyone help, please? I just want a working java source code with the
repository_user.xml.

Thanks