Mantis - Resin
Viewing Issue Advanced Details
2586 minor always 04-09-08 09:16 04-09-08 10:52
ferg  
ferg  
normal  
closed 3.0.26  
fixed  
none    
none 3.1.6  
0002586: Amber: multiple @OneToMany
(rep by Charles Lyons)

I have a model containing two objects:

Organisation (a company to which individuals may belong)
User (a user inside an organisation)

To make matters slightly more complicated, an organisation may "own"
another organisation, for example, a company which is part of a holding
group. Therefore:

A User has many-to-one correspondence with an Organisation [an Organisation
may have many users but a user has only one organisation]

An Organisation has many-to-one correspondence with a parent Organisation
[an Organisation may have only one "owner" but may own many]


The two classes:

@Entity
@Table(name="organisations")
public class Organisation {

   @Id
   @GeneratedValue
   private int id;

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name="ownerid")
   private Organisation owner; // the owner of this organisation, if any -
IS being initialised properly

   @OneToMany(mappedBy="owner",cascade=CascadeType.ALL)
   private Collection<Organisation> ownedOrganisations; // all the
organisations this one owns

   @OneToMany(mappedBy="organisation",cascade=CascadeType.ALL)
   private Collection<User> users; // all the users associated with this
organisation

   // getters/setters
}


@Entity
@Table(name="users")
public class User {

   @Id
   @GeneratedValue
   private int id;

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name="orgid")
   private Organisation organisation; // the organisation to which this
user belongs - this IS being initialised properly

   // getters/setters
}



Now it seems Amber cannot populate both @OneToMany collections in the
Organisation. If I remove one or the other then it will populate the
remaining one as expected. If I leave both in, only the first one (as it
appears listed in the source code) is populated and the second Collection
remains null (i.e. is not even initialised like most other collections are,
to empty collections). I see no reason why both should not be populated
according to the relations I specify. For reference, the relevant fields of
the database are:

Table organisations =================== id INT UNSIGNED PRIMARY KEY
AUTO_INCREMENT ownerid INT UNSIGNED --- reference to an organisations.id
for an owning organisation

Table users =========== id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT orgid
INT UNSIGNED -- reference to an organisations.id for the org to which this
user belongs


I've tested this on the 31st March snapshot. Is this a bug? Any idea when
the next snapshot will be released which might contain a fix?


Notes
(0002951)
ferg   
04-09-08 10:52   
jpa/0j06

Amber docs are at http://caucho.com/resin/doc/amber.xtp [^]