openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Simons <michael.sim...@optitool.de>
Subject Re: Weird problem with collections
Date Tue, 16 Jun 2009 16:35:35 GMT
Hello Mike,

I've to apologize because we've made two mistakes that lead to the problem described.

First of all we compared persistent objects by "==" what seems to work in a standalone
environment but fails when things come to the server and one of the objects is no more persistent.
Second we tried to access the collection when the object it's contained no longer was in the
persistence context. Of course it was not loaded any more.

Now that we corrected these things work like expected.

sorry,
Michael

Michael Dick schrieb:
> Hi Michael,
> 
> You are using FetchTypeLAZY though - so any relationships won't be loaded
> until needed (ie the accessor method is called).  Are you explicitly
> enhancing your entities in both environments? I believe subclassing loads
> collections eagerly in some circumstances (subclassing would take effect in
> JSE if you don't run the enhancer).
> 
> -mike
> 
> 
> On Mon, Jun 15, 2009 at 12:52 PM, Michael Simons <michael.simons@optitool.de
>> wrote:
> 
>> Hello,
>>
>> We've got a weird problem when fetching collections:
>> class A {
>>  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="a")
>>  private Set<B> bs;
>> }
>>
>> class B {
>>  @ManyToOne(fetch=FetchType.LAZY)
>>  @JoinColumn(name="a_id", nullable=false)
>>  private A a;
>> }
>>
>> Code to fetch instances of A (with collections of B)
>> Query query = em.createQuery ("select a from A a");
>> for (Object obj : query.getResultList ()) {
>>  cache.addA ((A)obj);
>> }
>>
>> When needed we access the A.bs to get one out of the collection.
>>
>> When done standalone everything works fine, but when running the same
>> within a stateful
>> SessionBean on an ApplicationServer (Geronimo) the collection is empty.
>> Even more weird: I can work-around the problem when iterating the
>> collection right after it was
>> fetched.
>> Any ideas, what I'm doing wrong (it doesn't depend on the FetchType)?
>>
>> kind regards,
>> Michael
>>
>>


Mime
View raw message