HHH-5280 Add test failing on multiple owners
This commit is contained in:
parent
af81f187b4
commit
0600527a6b
|
@ -0,0 +1,35 @@
|
||||||
|
package org.hibernate.test.annotations.engine.collection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.OrderColumn;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Cascade;
|
||||||
|
import org.hibernate.annotations.CascadeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "co_father")
|
||||||
|
public class Father {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
public Integer getId() { return id; }
|
||||||
|
public void setId(Integer id) { this.id = id; }
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@OneToMany
|
||||||
|
@OrderColumn(name = "son_arriv")
|
||||||
|
@JoinColumn(name = "father_id", nullable = false)
|
||||||
|
@Cascade({ CascadeType.SAVE_UPDATE })
|
||||||
|
public List<Son> getOrderedSons() { return orderedSons; }
|
||||||
|
public void setOrderedSons(List<Son> orderedSons) { this.orderedSons = orderedSons; }
|
||||||
|
private List<Son> orderedSons = new ArrayList<Son>( );
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.hibernate.test.annotations.engine.collection;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
import org.hibernate.annotations.Cascade;
|
||||||
|
import org.hibernate.annotations.CascadeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "co_mother")
|
||||||
|
public class Mother {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
public Integer getId() { return id; }
|
||||||
|
public void setId(Integer id) { this.id = id; }
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "mother")
|
||||||
|
@Cascade({ CascadeType.SAVE_UPDATE })
|
||||||
|
public Set<Son> getSons() { return sons; }
|
||||||
|
public void setSons(Set<Son> sons) { this.sons = sons; }
|
||||||
|
private Set<Son> sons = new HashSet<Son>();
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.hibernate.test.annotations.engine.collection;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name="co_son")
|
||||||
|
public class Son {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
public Integer getId() { return id; }
|
||||||
|
public void setId(Integer id) { this.id = id; }
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false) @JoinColumn(name = "father_id", insertable = false, updatable = false, nullable = false)
|
||||||
|
public Father getFather() { return father; }
|
||||||
|
public void setFather(Father father) { this.father = father; }
|
||||||
|
private Father father;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
public Mother getMother() { return mother; }
|
||||||
|
public void setMother(Mother mother) { this.mother = mother; }
|
||||||
|
private Mother mother;
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.hibernate.test.annotations.engine.collection;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.test.annotations.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
public class UnidirCollectionWithMultipleOwnerTest extends TestCase {
|
||||||
|
|
||||||
|
public void testUnidirCollectionWithMultipleOwner() throws Exception {
|
||||||
|
Session s = openSession();
|
||||||
|
Transaction tx;
|
||||||
|
tx = s.beginTransaction();
|
||||||
|
Father father = new Father();
|
||||||
|
Mother mother = new Mother();
|
||||||
|
s.save( father );
|
||||||
|
//s.save( mother );
|
||||||
|
Son son = new Son();
|
||||||
|
father.getOrderedSons().add( son );
|
||||||
|
son.setFather( father );
|
||||||
|
mother.getSons().add( son );
|
||||||
|
son.setMother( mother );
|
||||||
|
s.save( mother );
|
||||||
|
s.save( father );
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
s.clear();
|
||||||
|
|
||||||
|
tx = s.beginTransaction();
|
||||||
|
son = (Son) s.get( Son.class, son.getId() );
|
||||||
|
s.delete( son );
|
||||||
|
s.flush();
|
||||||
|
father = (Father) s.get( Father.class, father.getId() );
|
||||||
|
mother = (Mother) s.get( Mother.class, mother.getId() );
|
||||||
|
s.delete( father );
|
||||||
|
s.delete( mother );
|
||||||
|
tx.commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
return new Class<?>[] {
|
||||||
|
Father.class,
|
||||||
|
Mother.class,
|
||||||
|
Son.class
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue