Hi,
I've a mapped super class 'BaseEntity' that has common properties like
Date createdOn; Date updatedOn; boolean active; Company company; User
createdBy; etc.
Initially I used @EntityListeners defined at the BaseEntity and in
LifeCycleEvent handler on PrePersist(), I update these above common
properties.
I wanted my own instance of the listener(or to get hold of it), as I've to
update these from the UI module. But I couldn't find a way to do this in JPA
as it accepts only classes. Thanks to OpenJPA, I could achieve this easily
like this:
if (entityManagerFactory instanceof OpenJPAEntityManagerFactory) {
((OpenJPAEntityManagerFactory)
entityManagerFactory).addLifecycleListener(entityLifecycleHandler, (Class[])
null);
}
But in both the above cases, inside prePersist method, If I set the
properties of type Date or Boolean, they do not get saved.
Other properties like Company, User, etc. are saved properly.
Are the entities passed can not be modified in the listener? Or Is there any
other approach that could achieve this?
Thanks and Regards,
Prashant