External Entity Listener Bug #183

Closed
mevivs opened this Issue Feb 25, 2013 · 1 comment

1 participant

@mevivs
Collaborator

Raised by Dave

I think I've encountered an issue with using entity listeners defined in a separate class. If the argument of the handler method is of type Object, it works as expected

@Entity
@EntityListeners({UserHandler.class})
public class User {
// entity def. here
}

public class UserHandler {

@PrePersist
public void handlePrePersist(Object object) {
User user = (User) object;
}
}

However, if the argument type is changed to User i.e. we have

public void handlePrePersist(User user)

the handler is not processed.

This looks like a bug in the method getValidJPAAnnotationsFromMethod in the EntityListenersProcessor class : there is a comment in the code that says 'argument must be an Entity or Object' but only Object is allowed in the current implementation.

Kind regards,

Dave

As per JPA

Lifecycle Callback Methods
Entity lifecycle callback methods can be defined on an entity listener class and/or directly on an entity
class or mapped superclass.
Lifecycle callback methods are annotated with annotations designating the callback events for which
they are invoked or are mapped to the callback event using the XML descriptor.
The annotations used for callback methods on the entity class or mapped superclass and for callback
methods on the entity listener class are the same. The signatures of individual methods, however, differ.
Callback methods defined on an entity class or mapped superclass have the following signature:
void ()
Callback methods defined on an entity listener class have the following signature:
void (Object)
The Object argument is the entity instance for which the callback method is invoked. It may be
declared as the actual entity type.

It's a bug and proper fix needs to be added as per(JPA 2.0).

-Vivek

@mevivs mevivs was assigned Feb 25, 2013
@mevivs mevivs added a commit that referenced this issue Mar 7, 2013
@mevivs mevivs Added fix for Issue #183 c4c4166
@mevivs
Collaborator

Fixed and test case added.

@mevivs mevivs closed this Mar 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment