You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Esteve Boix <eb...@esteveb.com> on 2007/09/07 10:14:16 UTC

Re: Update & OneToMany

Hi there David,

Well I'm back on track with all this. I've updated to v1.0.0 (thanks for
the great work, BTW), and I'm still experiencing the problem.

Finally, I've been able to reproduce this outside my program, in an
isolated test.

I'm attaching the NetBeans project. This is an small description of what
is this doing:

Test1 method:
    Create a new parent object
    Store it in a map
    Persist it

Test2 method:
    Retrieve parent from map
    Add 2 childs
    Update it to database

Test3 method:
    Retrieve parent from map
    Add 2 childs more
    Update it to database

After Test3, I end up with a child table with 6 childs. 2 from the first
run (Test2), and 4 from the second run (Test3).
Debugging the program, I see that OpenJPA doesn't update the id of the
childs when I persist de parent, thus in the next run, it thinks that
the childs are new (that's my guess).

Are you able to reproduce this with this test ?

The mailing list server keeps rejecting this as spam, so please try to
download the test from http://www.esteveb.com/OpenJPATest.zip

Regards,
Esteve


En/na David Ezzio ha escrit:
> Hi Esteve,
>
> Glad to hear that you are making progress.  I was not able to reproduce 
> the behavior that you reported.  I'll send my project's zip to you 
> separately, since the Apache mail server is refusing the attachment 
> (apparently they have to be really, really small.)
>
> David
>
> Esteve Boix wrote:
>   
>> Hi there again,
>>
>> Just for the record: I finally set up a couple of simple tests, and I've
>> came to the conclusion that this is my fault (as I suspected :) ).
>>
>> When I run my DAOs in the test cases, using the Spring context all goes
>> well. The problem arises when I use the DAOs in a MINA's handler (just
>> for info: a MINA handler is like a Servlet, but for network connections,
>> not just HTTP. It's similar in that it has callbacks, a session object,
>> etc...).
>>
>> Well, if I run the DAO inside a MINA handler, when I persist an object
>> that have a OneToMany relation, the "id" fields of the child objects are
>> not updated, so in the next update, OpenJPA inserts again the entities
>> (which, again don't get their id fields updated). Strange.
>>
>> I've noticed that each method in the handler is called my a different
>> thread. I've tried "openjpa.multithreaded=true", but makes not difference.
>>
>> I'll come back to you when I find what's going on.
>>
>> Best regards,
>> Esteve
>>
>> En/na David Ezzio ha escrit:
>>     
>>> Hi Esteve,
>>>
>>> Doesn't sound normal.  Can you give us more info?  Some questions that 
>>> may help you understand what is going on.
>>>
>>> What are all the annotations for the OneToMany relationship?
>>>
>>> If Entity1 has a simple value attribute and you update that, does the 
>>> same behavior occur for the association?
>>>
>>> Is it possible that you have assigned a new collection to your field, 
>>> instead of modifying the existing collection?  If so, does the behavior 
>>> change if you change your application to modify the existing collection?
>>>
>>> HTH,
>>>
>>> David Ezzio
>>>
>>> Esteve Boix wrote:
>>>   
>>>       
>>>> Hi all,
>>>>
>>>> I'm observing the following behaviour, and I'd like to know if it's
>>>> normal or if it's a config problem:
>>>>
>>>> I have an Entity1 with a @OneToMany relation to Entity2, using a table
>>>> to link both entities. Everytime I update Entity1, OpenJPA deletes all
>>>> the links from the link table and recreates all the entities Entity2.
>>>> This is weird cause I end up with a lot of orphaned Entity2 objects
>>>> (OpenJPA clears the links, but not the original entities).
>>>>
>>>> Regards,
>>>> Esteve
>>>>
>>>>     
>>>>         
>>> Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
>>>
>>>
>>>   
>>>       
>>     
>
>
> Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.
>
>
>