-
15. Re: CustomEnversListener and Spring
inna1411 Sep 27, 2011 4:38 PM (in response to inna1411)I tied the way Adam suggested : no errors, but :
1. If I register AuditEventListener, REVINFO table was used and all audit tables populated
2. If I comment out AuditEventListener and don't specify any other one, audit tables were not populated.
-
16. Re: CustomEnversListener and Spring
adamw Sep 28, 2011 5:50 AM (in response to inna1411)Yes, of course you need to specify the event listener, it's a different thing than the revision entity.
Is the revision entity in the same jar that all other entities?
Adam -
17. Re: CustomEnversListener and Spring
inna1411 Sep 28, 2011 7:41 AM (in response to adamw)Yes, the revision entity (CustomRevisionEntity) resides in the same jar with other regular entities (annotated as @Entity).
Looks like AuditEventListener is not checking for annotation @RevisionEntity, but just uses REVINFO table by default.
-
18. Re: CustomEnversListener and Spring
adamw Sep 29, 2011 7:08 AM (in response to inna1411)Is the table for CustomRevisionEntity created by Hibernate (provided that your are using hbm2ddl=update or create-drop)?
Adam
-
19. Re: CustomEnversListener and Spring
inna1411 Sep 29, 2011 7:32 AM (in response to adamw)No, I created this table manually, and it resides (revision_info and tables with suffix _aud) in the same database file with auditable tables (it's Firebird; no schemas)
-
20. Re: CustomEnversListener and Spring
adamw Sep 29, 2011 8:50 AM (in response to inna1411)1 of 1 people found this helpfulCould you try persisting a new CustomRevisionEntity manually, to make sure that Hibernate sees that entity?
Adam
-
21. Re: CustomEnversListener and Spring
inna1411 Sep 29, 2011 9:39 AM (in response to adamw)I will try it.
What else I tried : I registered my listener CustomEnversListener and modified it this way
public class CustomEnversListener implements RevisionListener, PostUpdateEventListener {
...
public void onPostUpdate(PostUpdateEvent postUpdateEvent)
{
}
...
}
In this case I don't get any errors, update works fine and revision tables not populated (it's understandable why - my onPostUpdate is empty).
Looks like all is fine with listener itself; could be the problem persists with CustomRevisionEntity ?
-
22. Re: CustomEnversListener and Spring
adamw Sep 29, 2011 10:44 AM (in response to inna1411)Believe me, the EventListeners don't have anything to do here
Adam
-
23. Re: CustomEnversListener and Spring
inna1411 Sep 29, 2011 11:06 AM (in response to adamw)Sure, I believe you ! It's just was a try ... (I saw on web one user mentioned exception will go away if we change the listener this way).
I just wanted to make sure the listener "listens".
-
24. Re: CustomEnversListener and Spring
inna1411 Sep 29, 2011 1:04 PM (in response to adamw)Adam,
I tried to persist a new CustomRevisionEntity manually, and log contains :
.......CustomRevisionEntityHibernate.entity is null false
Hibernate: select gen_id( hibernate_sequence, 1 ) from RDB$DATABASE
Hibernate: insert into revision_info (REVTSTMP, username, REV) values (?, ?, ?)
and table has been populated.
But via listener :
java.lang.ArrayStoreException: com.etranscor.domain.audit.CustomEnversListener
at org.hibernate.cfg.Configuration.setListener(Configuration.java:1722)
-
25. Re: CustomEnversListener and Spring
inna1411 Sep 29, 2011 3:48 PM (in response to adamw)Adam,
all is fine now : the problem was in entity. Don't know how, but it was using hibernate.annotations.Entity instead of javax.persistense.Entity (my word, initially it was right; probably, after manipulating the code for listener I dropped the import statement, and the the wrong one was inserted.)
So, for all other users having the same problem :
in my case I registered in Spring the default listener AuditEventListener, created CustomRevisionEntity with annotaion @RevisionEntity(CustomEnversListener.class) & CustomEnversListener (see code in the beginning of this thread).
CustomRevisionEntity I registered in Spring application-context.xml under sessionFactory bean this way :
<property name="annotatedClasses">
<list>
<value>com.etranscor.domain.audit.CustomRevisionEntity</value>
</list>
</property>
Please pay attention to import statement for @Entity in CustomRevisionEntity : it must be "import javax.persistence.Entity;"
The only problem left : how to get the real user value (inside the code and manual insert into revision_info table this code worked :
String user= SecurityContextHolder.getContext().getAuthentication().getName();
But in my jar that keeps only entities, it's null.
)
Anyway, thank you very much for help and a great hint !