2015-05-04 64 views
0

我與Hibernate Envers更新,我試圖生成audity表,都沒有成功:(...我使用hibernate-core-3.5.6-Final.jarhibernate-envers-3.5.6-Final.jar使用Ant和休眠envers創建audity表

我第一次嘗試是創造。直接audity表中設置hbm2ddl.auto屬性爲updatehibernate.cfg.xml

<hibernate-configuration> 
<session-factory> 
... 
    <property name="hbm2ddl.auto">update</property> 
    <property name="hibernate.ejb.event.post-insert">org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener</property> 
    <property name="hibernate.ejb.event.post-update">org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener</property> 
    <property name="hibernate.ejb.event.post-delete">org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener</property> 
    <property name="hibernate.ejb.event.pre-collection-update">org.hibernate.envers.event.AuditEventListener</property> 
    <property name="hibernate.ejb.event.pre-collection-remove">org.hibernate.envers.event.AuditEventListener</property> 
    <property name="hibernate.ejb.event.post-collection-recreate">org.hibernate.envers.event.AuditEventListene</property> 
... 
</session-factory> 

我的審計類是類似以下內容:

@Entity 
@Audited 
@Table(name = "EAL_USUS_USUARIOS", uniqueConstraints = @UniqueConstraint(columnNames = { 
    "BIC_ENTIDAD", "ID_INTERNO_ENTIDAD" })) 
public class EalUsusUsuarios implements java.io.Serializable { 

但更新命令忽略audity表,所以我試圖創建一個Ant任務生成模式DDL文件,所以在我build.xml文件中,有一個任務,如:

<target name="schemaexport" description="Exports a generated schema to DB and file"> 
    <echo message="generación schema "/> 
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.EnversHibernateToolTask" 
    classpath="${CK_JARS}/hibernate-envers-3.5.6-Final.jar"/> 
<hibernatetool destdir="${clases.dir}"> 
    <classpath> 
     <fileset refid="hibernate-envers-3.5.6-Final.jar" /> 
     <path location="${CK_JARS}/" /> 
    </classpath> 
    <jpaconfiguration persistenceunit="ConsolePU" /> 
    <hbm2ddl 
     drop="false" 
     create="true" 
     export="false" 
     outputfilename="C:/Desarrollo/versioning-ddl.sql" 
     delimiter=";" 
     format="true"/> 
    </hibernatetool> 
</target> 

這個配置顯然不工作,因爲我不確定應該在classpath中設置什麼值。我雖然那是envers jar所在的目錄,但我得到了「taskdef類org.hibernate.tool.ant.EnversHibernateToolTask所需的類無法找到:org/hibernate/tool/ant/HibernateToolTask」來自ant控制檯的錯誤消息。

任何有關在這兩種方式中的任何一個都存在問題的想法?

回答

0

我會回答自己,並希望儘量爲他人做好準備。

首先,我幾乎瘋狂地試圖配置我的hibernate.cfg.xml以便能夠使用envers。最後,我放棄了這個選項,並轉移到JPA 2.0。要設置jpa配置,需要在您的WEB-INF/classes/META-INF目錄中有persistence.xml。在我的情況下,這個檔案似乎如下:

?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence    
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
<persistence-unit name="****" transaction-type="JTA"> 
<provider>org.hibernate.ejb.HibernatePersistence</provider> 
<jta-data-source>java:/jdbc/EaliaPagosDTSource</jta-data-source> 
<class>es.cecabank.ealiapagos.accesobd.model.EalUsusMediospEsts</class> 
<class>es.cecabank.ealiapagos.accesobd.model.EalUsusAliasEsts</class> 
... 
<properties> 
    <!-- property name="javax.persistence.transactionType" 
    value="RESOURCE_LOCAL" /--> 
    <property name="hibernate.bytecode.use_reflection_optimizer" value="false"/> 
    <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/> 
    <property name="javax.persistence.jdbc.password" value="****"/> 
    <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:********"/> 
    <property name="javax.persistence.jdbc.user" value="****"/> 
    <property name="javax.persistence.jdbc.default_schema" value="****"/> 
    <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" /> 
    <property name="hibernate.show_sql" value="true"/> 
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect"/> 
    <property name="hibernate.search.autoregister_listeners" value="false" /> 
    <property name="hibernate.current_session_context_class" value="thread"/> 
    <property name="show_sql" value="true"/> 
    <property name="hibernate.hbm2ddl.auto" value="update" /> 
</properties> 
</persistence-unit> 
</persistence> 

請注意,我正在設置JTA配置爲transation類型。這是非常重要的,因爲您管理交易的方式取決於此值。在我的情況下,我使用<jta-data-source>標記中定義的數據源進行事務處理,其中指的是在JBOSS配置文件standalone.xml中聲明的數據源。我標誌着我與@Audited註釋和審計表實體是在我部署我的應用程序在JBOSS 7.1

如果任何一個需要更多細節的那一刻automaticallye產生的,不要猶豫,問