java - Why Hibernate Envers is ignoring my custom RevisionEntity? -
i'm developing application using jpa 2.1 (supported hibernate 4.2.11) spring 4.0.2. using envers auditing changes in project entities. working fine. problem comes when try use custom revision entity envers documentation says: http://docs.jboss.org/hibernate/core/4.1/devguide/en-us/html/ch15.html#envers-revisionlog
we have made custom class , custom listener pointed in documentation seems totally ignored hibernate. custom classes:
@entity @revisionentity(auditingrevisionlistener.class) public class auditedrevisionentity extends defaultrevisionentity { private string username; public string getusername() { return username; } public void setusername(string username) { this.username = username; } } public class auditingrevisionlistener implements revisionlistener { private static log log = logfactory.getlog(auditingrevisionlistener.class.getname()); @override public void newrevision(object revisionentity) { auditedrevisionentity reventity = (auditedrevisionentity) revisionentity; string username = securitycontextholder.getcontext().getauthentication().getname(); reventity.setusername(username); } }
it's hibernate not taking account classes because should enough tom make work use annotation: @revisionentity(auditingrevisionlistener.class). other annotated entities recognized ignored. have in our spring config (we dont use persistence.xml) base packages scanned when loading spring context:
<context:component-scan base-package="our.basepackage" />
is enough?
we have tried aproach. set manually revision listener property in entitymanagerfactory configuration
<prop key="org.hibernate.envers.revision_listener">our.basepackage.auditingrevisionlistener</prop>
but classcastexception in first line of newrevision method because parameter revisionentity not of class auditedrevisionentity. again class auditedrevisionentity not loaded.
i supose it's simple question i'm unable guess why @revisionentity annotation beeing ignored. idea?
finally got problem was. suspects right, hibernate ignoring envers classes because of param in entitymanagerfactory configuration:
<property name="packagestoscan" value="our.basepackage.otherpackage" />
we need tell hibernate check 'our.basepackage'. silly problem easy solution.
Comments
Post a Comment