openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Struberg (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OPENJPA-1873) EntityManager#merge sometimes passes wrong entity values to @PostLoad EntityListeners
Date Fri, 09 Dec 2011 11:48:40 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-1873?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13166110#comment-13166110
] 

Mark Struberg commented on OPENJPA-1873:
----------------------------------------

Thanks for the review Kevin!

Indeed, the problem I faced for a long time was that PostLoad was pretty much broken, because
the payload entity you get into this event was always different, depending on the situation.

I agree with what Rick and Pinaki pointed out above, that the spec is not really clear if
PostLoad should get fired for a merge at all. But OpenJPA actually _did_ fire it in _some_
cases, and the entity which got handed to the event was a mixture between the entity in memory,
the state on the database and the lazy-loaded delta. Again: it was not _one_ of those 3, but
it was a weird mixture with some fields nulled out, etc. And it was depending on _loaded,
_dirty and the detached state. So basically the PostLoad event was not usable for users once
the entity got detached.

Because of that, I would be in favour to even make PostLoadOnMerge enabled by default - but
that's a policy decision which is not up to me to decide. Please note that the behaviour only
got changed if there is any PostLoad lifecycle listener registered on the entity at all! 
With the PostLoadOnMerge flag enabled, OpenJPA now behaves the same way as I saw with latest
Hibernate and EclipseLink - I actually don't care much about those other impls, but I think
it's at least not a bad thing ;)

I was not really sure about the String property based configuration, so I decided to go full
route. If you say this is not supported anymore in openjpa-2.x, then we should think about
Deprecating those parts at all?

Regarding the documentation - thanks for the pointer! I thought those get generated out from
the JavaDoc. Will fix those parts in the doc by adding the property.


                
> EntityManager#merge sometimes passes wrong entity values to @PostLoad EntityListeners

> --------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1873
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1873
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.0.0, 2.0.1, 2.0.2
>            Reporter: Mark Struberg
>            Assignee: Mark Struberg
>             Fix For: 2.2.0
>
>         Attachments: OPENJPA-1873-fix1.patch, OPENJPA-1873-fix2.patch, OPENJPA-1873-fix3.patch,
OPENJPA-1873-unittest.patch, openjpa-1873-hack-1.patch, postloadtest.zip
>
>
> I've tested this with the latest from branches/2.0.x.
> My entity has an @EntityListeners which observes the @PostLoad lifecycle event. This
listener stores the 'old' values from the database for later use (see http://struberg.wordpress.com/2010/07/31/howto-changelog-with-jpa/
for the intention behind). All works well if the table has only a few rows. But if you add
more rows, OpenJPA tries to optimize the access and only loads the @Version field + the dirty
fields. In this case the merging seems to be wrong, because I get the NEW values from the
dirty fields instead of the original values from the database passed to my @PostLoad method.
> Did cost me a few grey hairs to track down the differences between the working and the
broken scenarios here ;) But finally I was able to creat a unit test showing the problem

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message