Skip to content

Commit

Permalink
Fix for Issue liquibase#27: Hibernate4: Envers tables not generated
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Dettlaff committed Jun 21, 2014
1 parent 4c764be commit defa89f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.envers.configuration.spi.AuditConfiguration;

/**
* Base class for all Hibernate Databases. This extension interacts with Hibernate by creating standard liquibase.database.Database implementations that
Expand Down Expand Up @@ -44,6 +45,7 @@ public void setConnection(DatabaseConnection conn) {
this.configuration = buildConfiguration(((HibernateConnection) ((JdbcConnection) conn).getUnderlyingConnection()));

this.configuration.buildMappings();
AuditConfiguration.getFor(configuration);
this.dialect = configureDialect();

afterSetup();
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/example/ejb3/auction/AuditedItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.ejb3.auction;

import javax.persistence.*;

import org.hibernate.envers.Audited;

@Audited
@Entity
public class AuditedItem {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="AUDITED_ITEM_SEQ")
@SequenceGenerator(name="AUDITED_ITEM_SEQ",sequenceName="AUDITED_ITEM_SEQ")
private long id;
@Column(unique = true)
private String name;

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.envers.configuration.spi.AuditConfiguration;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl;
import org.hibernate.jpa.boot.spi.Bootstrap;
Expand Down Expand Up @@ -211,7 +212,10 @@ private Configuration createSpringPackageScanningConfiguration(boolean enhancedI
EntityManagerFactoryBuilderImpl builder = (EntityManagerFactoryBuilderImpl) Bootstrap.getEntityManagerFactoryBuilder(persistenceUnitInfo,
jpaPropertyMap, null);
ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
return builder.buildHibernateConfiguration(serviceRegistry);
Configuration configuration = builder.buildHibernateConfiguration(serviceRegistry);
configuration.buildMappings();
AuditConfiguration.getFor(configuration);
return configuration;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public static void assertEjb3HibernateMapped(DatabaseSnapshot snapshot) {
hasProperty("name", is("AuctionInfo")),
hasProperty("name", is("AuctionItem")),
hasProperty("name", is("Item")),
hasProperty("name", is("AuditedItem")),
hasProperty("name", is("AuditedItem_AUD")),
hasProperty("name", is("REVINFO")),
hasProperty("name", is("WatcherSeqTable"))));


Expand Down Expand Up @@ -90,6 +93,9 @@ public void ejb3UrlWithNamingStrategy() throws Exception {
hasProperty("name", is("auction_info")),
hasProperty("name", is("auction_item")),
hasProperty("name", is("item")),
hasProperty("name", is("audited_item")),
hasProperty("name", is("audited_item_aud")),
hasProperty("name", is("revinfo")),
hasProperty("name", is("WatcherSeqTable"))));

}
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<class>com.example.ejb3.auction.User</class>
<class>com.example.ejb3.auction.Watcher</class>
<class>com.example.ejb3.auction.Item</class>
<class>com.example.ejb3.auction.AuditedItem</class>
<properties>
<property name="hibernate.archive.autodetection" value="false"/>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
Expand Down

0 comments on commit defa89f

Please sign in to comment.