HHH-4634:
- testcase git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18113 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
b46895ff17
commit
07ec77023e
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test.entities.manytomany.biowned;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.persistence.*;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* Entity owning a many-to-many relation, where the other entity also owns the relation.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class ListBiowning1Entity {
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
private String data;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "biowning",
|
||||
joinColumns = @JoinColumn(name = "biowning1_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "biowning2_id", insertable = false, updatable = false)
|
||||
)
|
||||
private List<ListBiowning2Entity> references = new ArrayList<ListBiowning2Entity>();
|
||||
|
||||
public ListBiowning1Entity() { }
|
||||
|
||||
public ListBiowning1Entity(Integer id, String data) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ListBiowning1Entity(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<ListBiowning2Entity> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<ListBiowning2Entity> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ListBiowning1Entity)) return false;
|
||||
|
||||
ListBiowning1Entity that = (ListBiowning1Entity) o;
|
||||
|
||||
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
||||
//noinspection RedundantIfStatement
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (id != null ? id.hashCode() : 0);
|
||||
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ListBiowning1Entity(id = " + id + ", data = " + data + ")";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test.entities.manytomany.biowned;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.persistence.*;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
/**
|
||||
* Entity owning a many-to-many relation, where the other entity also owns the relation.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@Entity
|
||||
@Audited
|
||||
public class ListBiowning2Entity {
|
||||
@Id
|
||||
private Integer id;
|
||||
|
||||
private String data;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "biowning",
|
||||
joinColumns = @JoinColumn(name = "biowning2_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "biowning1_id", insertable = false, updatable = false)
|
||||
)
|
||||
private List<ListBiowning1Entity> references = new ArrayList<ListBiowning1Entity>();
|
||||
|
||||
public ListBiowning2Entity() { }
|
||||
|
||||
public ListBiowning2Entity(Integer id, String data) {
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ListBiowning2Entity(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public List<ListBiowning1Entity> getReferences() {
|
||||
return references;
|
||||
}
|
||||
|
||||
public void setReferences(List<ListBiowning1Entity> references) {
|
||||
this.references = references;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ListBiowning2Entity)) return false;
|
||||
|
||||
ListBiowning2Entity that = (ListBiowning2Entity) o;
|
||||
|
||||
if (data != null ? !data.equals(that.data) : that.data != null) return false;
|
||||
//noinspection RedundantIfStatement
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (id != null ? id.hashCode() : 0);
|
||||
result = 31 * result + (data != null ? data.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ListBiowning2Entity(id = " + id + ", data = " + data + ")";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.test.integration.manytomany.biowned;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.manytomany.biowned.ListBiowning1Entity;
|
||||
import org.hibernate.envers.test.entities.manytomany.biowned.ListBiowning2Entity;
|
||||
import org.hibernate.envers.test.tools.TestTools;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class BasicBiowned extends AbstractEntityTest {
|
||||
private Integer o1_1_id;
|
||||
private Integer o1_2_id;
|
||||
private Integer o2_1_id;
|
||||
private Integer o2_2_id;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
//cfg.addAnnotatedClass(ListBiowning1Entity.class);
|
||||
//cfg.addAnnotatedClass(ListBiowning2Entity.class);
|
||||
}
|
||||
|
||||
//@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
EntityManager em = getEntityManager();
|
||||
|
||||
ListBiowning1Entity o1_1 = new ListBiowning1Entity("o1_1");
|
||||
ListBiowning1Entity o1_2 = new ListBiowning1Entity("o1_2");
|
||||
ListBiowning2Entity o2_1 = new ListBiowning2Entity("o2_1");
|
||||
ListBiowning2Entity o2_2 = new ListBiowning2Entity("o2_2");
|
||||
|
||||
// Revision 1
|
||||
em.getTransaction().begin();
|
||||
|
||||
em.persist(o1_1);
|
||||
em.persist(o1_2);
|
||||
em.persist(o2_1);
|
||||
em.persist(o2_2);
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2 (1_1 <-> 2_1; 1_2 <-> 2_2)
|
||||
|
||||
em.getTransaction().begin();
|
||||
|
||||
o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
|
||||
o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId());
|
||||
o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId());
|
||||
o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
|
||||
|
||||
o1_1.getReferences().add(o2_1);
|
||||
o1_2.getReferences().add(o2_2);
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 3 (1_1 <-> 2_1, 2_2; 1_2 <-> 2_2)
|
||||
em.getTransaction().begin();
|
||||
|
||||
o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
|
||||
o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
|
||||
|
||||
o1_1.getReferences().add(o2_2);
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 4 (1_1 <-> 2_1; 1_2 <-> 2_1)
|
||||
em.getTransaction().begin();
|
||||
|
||||
o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
|
||||
o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId());
|
||||
o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId());
|
||||
o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
|
||||
|
||||
o2_2.getReferences().remove(o1_1);
|
||||
o2_1.getReferences().remove(o1_1);
|
||||
o1_2.getReferences().add(o2_1);
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 5 (1_2 <-> 2_1, 2_2)
|
||||
em.getTransaction().begin();
|
||||
|
||||
o1_1 = em.find(ListBiowning1Entity.class, o1_1.getId());
|
||||
o1_2 = em.find(ListBiowning1Entity.class, o1_2.getId());
|
||||
o2_1 = em.find(ListBiowning2Entity.class, o2_1.getId());
|
||||
o2_2 = em.find(ListBiowning2Entity.class, o2_2.getId());
|
||||
|
||||
o2_1.getReferences().remove(o1_1);
|
||||
o1_1.getReferences().remove(o2_1);
|
||||
o1_2.getReferences().add(o2_2);
|
||||
o2_2.getReferences().add(o1_2);
|
||||
|
||||
em.getTransaction().commit();
|
||||
|
||||
//
|
||||
|
||||
o1_1_id = o1_1.getId();
|
||||
o1_2_id = o1_2.getId();
|
||||
o2_1_id = o2_1.getId();
|
||||
o2_2_id = o2_2.getId();
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testRevisionsCounts() {
|
||||
assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ListBiowning1Entity.class, o1_1_id));
|
||||
assert Arrays.asList(1, 2, 4, 5).equals(getAuditReader().getRevisions(ListBiowning1Entity.class, o1_2_id));
|
||||
|
||||
assert Arrays.asList(1, 2, 4, 5).equals(getAuditReader().getRevisions(ListBiowning2Entity.class, o2_1_id));
|
||||
assert Arrays.asList(1, 2, 3, 4, 5).equals(getAuditReader().getRevisions(ListBiowning2Entity.class, o2_2_id));
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testHistoryOfO1_1() {
|
||||
ListBiowning2Entity o2_1 = getEntityManager().find(ListBiowning2Entity.class, o2_1_id);
|
||||
ListBiowning2Entity o2_2 = getEntityManager().find(ListBiowning2Entity.class, o2_2_id);
|
||||
|
||||
ListBiowning1Entity rev1 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 1);
|
||||
ListBiowning1Entity rev2 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 2);
|
||||
ListBiowning1Entity rev3 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 3);
|
||||
ListBiowning1Entity rev4 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 4);
|
||||
ListBiowning1Entity rev5 = getAuditReader().find(ListBiowning1Entity.class, o1_1_id, 5);
|
||||
|
||||
assert TestTools.checkList(rev1.getReferences());
|
||||
assert TestTools.checkList(rev2.getReferences(), o2_1);
|
||||
assert TestTools.checkList(rev3.getReferences(), o2_1, o2_2);
|
||||
assert TestTools.checkList(rev4.getReferences(), o2_1);
|
||||
assert TestTools.checkList(rev5.getReferences());
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testHistoryOfO1_2() {
|
||||
ListBiowning2Entity o2_1 = getEntityManager().find(ListBiowning2Entity.class, o2_1_id);
|
||||
ListBiowning2Entity o2_2 = getEntityManager().find(ListBiowning2Entity.class, o2_2_id);
|
||||
|
||||
ListBiowning1Entity rev1 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 1);
|
||||
ListBiowning1Entity rev2 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 2);
|
||||
ListBiowning1Entity rev3 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 3);
|
||||
ListBiowning1Entity rev4 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 4);
|
||||
ListBiowning1Entity rev5 = getAuditReader().find(ListBiowning1Entity.class, o1_2_id, 5);
|
||||
|
||||
assert TestTools.checkList(rev1.getReferences());
|
||||
assert TestTools.checkList(rev2.getReferences(), o2_2);
|
||||
assert TestTools.checkList(rev3.getReferences(), o2_2);
|
||||
assert TestTools.checkList(rev4.getReferences(), o2_1);
|
||||
assert TestTools.checkList(rev5.getReferences(), o2_1, o2_2);
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testHistoryOfO2_1() {
|
||||
ListBiowning1Entity o1_1 = getEntityManager().find(ListBiowning1Entity.class, o1_1_id);
|
||||
ListBiowning1Entity o1_2 = getEntityManager().find(ListBiowning1Entity.class, o1_2_id);
|
||||
|
||||
ListBiowning2Entity rev1 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 1);
|
||||
ListBiowning2Entity rev2 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 2);
|
||||
ListBiowning2Entity rev3 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 3);
|
||||
ListBiowning2Entity rev4 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 4);
|
||||
ListBiowning2Entity rev5 = getAuditReader().find(ListBiowning2Entity.class, o1_1_id, 5);
|
||||
|
||||
assert TestTools.checkList(rev1.getReferences());
|
||||
assert TestTools.checkList(rev2.getReferences(), o1_1);
|
||||
assert TestTools.checkList(rev3.getReferences(), o1_1);
|
||||
assert TestTools.checkList(rev4.getReferences(), o1_1, o1_2);
|
||||
assert TestTools.checkList(rev5.getReferences(), o1_2);
|
||||
}
|
||||
|
||||
@Test(enabled = false)
|
||||
public void testHistoryOfO2_2() {
|
||||
ListBiowning1Entity o1_1 = getEntityManager().find(ListBiowning1Entity.class, o1_1_id);
|
||||
ListBiowning1Entity o1_2 = getEntityManager().find(ListBiowning1Entity.class, o1_2_id);
|
||||
|
||||
ListBiowning2Entity rev1 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 1);
|
||||
ListBiowning2Entity rev2 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 2);
|
||||
ListBiowning2Entity rev3 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 3);
|
||||
ListBiowning2Entity rev4 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 4);
|
||||
ListBiowning2Entity rev5 = getAuditReader().find(ListBiowning2Entity.class, o1_2_id, 5);
|
||||
|
||||
assert TestTools.checkList(rev1.getReferences());
|
||||
assert TestTools.checkList(rev2.getReferences(), o1_2);
|
||||
assert TestTools.checkList(rev3.getReferences(), o1_1, o1_2);
|
||||
assert TestTools.checkList(rev4.getReferences());
|
||||
assert TestTools.checkList(rev5.getReferences(), o1_2);
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
<package name="org.hibernate.envers.test.integration.interfaces.components" />
|
||||
<package name="org.hibernate.envers.test.integration.interfaces.relation" />
|
||||
<package name="org.hibernate.envers.test.integration.manytomany" />
|
||||
<package name="org.hibernate.envers.test.integration.manytomany.biowned" />
|
||||
<package name="org.hibernate.envers.test.integration.manytomany.sametable" />
|
||||
<package name="org.hibernate.envers.test.integration.manytomany.ternary" />
|
||||
<package name="org.hibernate.envers.test.integration.manytomany.unidirectional" />
|
||||
|
|
Loading…
Reference in New Issue