Hi friends. I need to Audit several classes and to say to hibernate that the class TEST1 need to audit when its INSERT, but the TEST2 need to audit when INSERT AND UPDATE. When in the HIBERNATE file I set the following source all is ok and the hibernate to audit all (insert, update, delete) of Test1 and Test2:
<listener type="pre-delete" class="auditar.HibernateAuditLogListener"/> <listener type="pre-update" class="auditar.HibernateAuditLogListener"/> <listener type="pre-insert" class="auditar.HibernateAuditLogListener"/> <listener type="pre-load" class="auditar.HibernateAuditLogListener"/>
but I need to divide the auditing (I don't need to audit all), so that I configured the HIBERNATE whit the next source .
It is my HIBERNATE.CFG.XML :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property> <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@HOST:1521:SHEMA</property> <property name="hibernate.connection.username">USER</property> <property name="hibernate.connection.password">PASSWORD</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.show_sql">true</property>
<!-- Audit class --> <mapping resource="modelo/AuditTrail.hbm.xml"/> <!-- Class for auditing --> <mapping resource="modelo/Test1.hbm.xml"/> <mapping resource="modelo/Test2.hbm.xml"/>
<!-- Listener IT IS THE ERROR --> <entity class="models.Test"> <entity-listeners> <entity-listener class="audit.HibernateAuditLogListener"> <pre-insert method-name="onPreInsert"/> </entity-listener> </entity-listeners> </entity>
<entity class="models.Test2"> <entity-listeners> <entity-listener class="audit.HibernateAuditLogListener"> <pre-insert method-name="onPreInsert"/> <pre-insert method-name="onPreUpdate"/> </entity-listener> </entity-listeners> </entity> <!-- END LISTENER -->
</session-factory> </hibernate-configuration>
After run my project I get the following error message
Caused by: org.hibernate.MappingException: invalid configuration at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1487) at org.hibernate.cfg.Configuration.configure(Configuration.java:1428) at org.hibernate.cfg.Configuration.configure(Configuration.java:1414) at conexion.HibSession.<clinit>(HibSession.java:22) ... 81 more Caused by: org.xml.sax.SAXParseException: Element type "entity" must be declared. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
I need to know how to do that auditing because I need so.
Thanks. God Bless you. Angel
|