I had some similar issues when loading a large number of data records that
included some joins, I found that if I called the clear function on he
EntityManager every x records it resolved my issue, also solved my OOM
issues also.  

Hth

Chris


-----Original Message-----
From: Christopher Giblin [mailto:[email protected]] 
Sent: Saturday, 16 January 2010 12:38 AM
To: [email protected]
Subject: Re: empty collections

Hi,
Solved. Problem was that both sides of the bi-directional relationship were
not being assigned before persisting, just one side :

  user.getGroups().add(group);

The following fixed the problem:

  user.getGroups().add(group);
  group.getUsers().add(user);

Interesting that by restarting the app, the relationships could be read,
just not after persisting.

Thanks, chris



> Hi,
> I have a bidirectional many-to-many relationship between two
> entities. Each entity references a collection of the other entity.
>
> I import data, then retrieve entities with a query. However, when I
> refer to an entity's collection, its size is always  0 (eg,
> group.getUsers().size() is  0).  I look into the db and the join
> table is filled correctly. I restart the app, and then the same
> entity correctly returns the collection. That is, group.getUsers
> ().size() is now > 0 and I can access the collection's elements.
>
> I am wondering is this is a known pattern and there is an a-ha out
> there. Otherwise OpenJPA is working great!
>
> Thanks,
> chris

Reply via email to