HHH-3736: fix and testcase.
Thank you to Erik-Berndt Scheper for providing the patches! git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15834 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
4bd552cfdb
commit
e6c9326438
|
@ -32,6 +32,7 @@ import org.hibernate.envers.entities.mapper.id.IdMapper;
|
|||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.tools.reflection.ReflectionTools;
|
||||
import org.hibernate.util.ReflectHelper;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
|
@ -80,7 +81,7 @@ public class EntityInstantiator {
|
|||
Object ret;
|
||||
try {
|
||||
Class<?> cls = ReflectionTools.loadClass(entityName);
|
||||
ret = cls.newInstance();
|
||||
ret = ReflectHelper.getDefaultConstructor(cls).newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new AuditException(e);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package org.hibernate.envers.test.integration.accesstype;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@Audited
|
||||
public class Country {
|
||||
@Id
|
||||
@Column(length = 4)
|
||||
private Integer code;
|
||||
|
||||
@Column(length = 40)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Default constructor for persistence provider.
|
||||
*/
|
||||
@SuppressWarnings({"UnusedDeclaration"})
|
||||
private Country() { }
|
||||
|
||||
private Country(Integer code, String naam) {
|
||||
this.code = code;
|
||||
this.name = naam;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static Country of(Integer code, String name) {
|
||||
return new Country(code, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((code == null) ? 0 : code.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Country other = (Country) obj;
|
||||
if (code == null) {
|
||||
if (other.code != null)
|
||||
return false;
|
||||
} else if (!code.equals(other.code))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.hibernate.envers.test.integration.accesstype;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
public class ImmutableClassAccessType extends AbstractEntityTest {
|
||||
private Country country;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(Country.class);
|
||||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
EntityManager em = getEntityManager();
|
||||
|
||||
// Revision 1
|
||||
em.getTransaction().begin();
|
||||
country = Country.of(123, "Germany");
|
||||
em.persist(country);
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCounts() {
|
||||
assert Arrays.asList(1)
|
||||
.equals(
|
||||
getAuditReader().getRevisions(Country.class,
|
||||
country.getCode()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfId1() {
|
||||
Country country1 = getEntityManager().find(Country.class,
|
||||
country.getCode());
|
||||
assertEquals(country1, country);
|
||||
|
||||
Country history = getAuditReader().find(Country.class, country1.getCode(), 1);
|
||||
assertEquals(country, history);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue