HHH-13900: replaced all spaces by tabs, assigned jira key to test, removed todo to assign jira key to test
This commit is contained in:
parent
9a8296411a
commit
f9678c9715
|
@ -281,8 +281,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
|
|||
|
||||
new ForeignKeys.Nullifier( entity, true, false, session, persister ).nullifyTransientReferences( entityEntry.getDeletedState() );
|
||||
new Nullability( session ).checkNullability( entityEntry.getDeletedState(), persister, Nullability.NullabilityCheckType.DELETE );
|
||||
if( persister.getClassMetadata() != null && !persister.getClassMetadata().keepReference() ) {
|
||||
persistenceContext.registerNullifiableEntityKey(key);
|
||||
if ( persister.getClassMetadata() != null && !persister.getClassMetadata().keepReference() ) {
|
||||
persistenceContext.registerNullifiableEntityKey( key );
|
||||
}
|
||||
|
||||
if ( isOrphanRemovalBeforeUpdates ) {
|
||||
|
|
|
@ -21,13 +21,13 @@ import java.util.Set;
|
|||
@Where(clause = "deleted = false")
|
||||
public class DeathStar extends BaseEntity {
|
||||
|
||||
@NotNull
|
||||
@NotNull
|
||||
@OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
private Vader vader;
|
||||
@OneToMany(cascade = CascadeType.MERGE, orphanRemoval = true, mappedBy = "deathStar",fetch = FetchType.EAGER)
|
||||
private Set<Trooper> troppers;
|
||||
@NotNull
|
||||
@OneToOne(optional = false, fetch = FetchType.EAGER)
|
||||
@NotNull
|
||||
@OneToOne(optional = false, fetch = FetchType.EAGER)
|
||||
private Universe universe;
|
||||
|
||||
public Vader getVader() {
|
||||
|
@ -46,11 +46,11 @@ public class DeathStar extends BaseEntity {
|
|||
this.troppers = troppers;
|
||||
}
|
||||
|
||||
public Universe getUniverse() {
|
||||
return universe;
|
||||
}
|
||||
public Universe getUniverse() {
|
||||
return universe;
|
||||
}
|
||||
|
||||
public void setUniverse(Universe universe) {
|
||||
this.universe = universe;
|
||||
}
|
||||
public void setUniverse(Universe universe) {
|
||||
this.universe = universe;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,95 +25,95 @@ public class KeepReferenceTest extends BaseCoreFunctionalTestCase {
|
|||
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-XXXXX")//TODO: assign jira key
|
||||
@TestForIssue( jiraKey = "HHH-13900")
|
||||
public void keepReferenceShouldKeepReference(){
|
||||
Transaction transaction;
|
||||
Transaction transaction;
|
||||
Session session = openSession();
|
||||
transaction = session.beginTransaction();
|
||||
transaction = session.beginTransaction();
|
||||
|
||||
Universe universe = new Universe();
|
||||
session.save(universe);
|
||||
Universe universe = new Universe();
|
||||
session.save(universe);
|
||||
|
||||
DeathStar deathStar = new DeathStar();
|
||||
deathStar.setUniverse(universe);
|
||||
universe.setDeathStar(deathStar);
|
||||
DeathStar deathStar = new DeathStar();
|
||||
deathStar.setUniverse(universe);
|
||||
universe.setDeathStar(deathStar);
|
||||
|
||||
Vader vader = new Vader();
|
||||
vader.setDeathStar(deathStar);
|
||||
Vader vader = new Vader();
|
||||
vader.setDeathStar(deathStar);
|
||||
|
||||
deathStar.setVader(vader);
|
||||
session.save(deathStar);
|
||||
deathStar.setVader(vader);
|
||||
session.save(deathStar);
|
||||
|
||||
Trooper trooper = new Trooper();
|
||||
trooper.setCode("TK-421");
|
||||
trooper.setDeathStar(deathStar);
|
||||
deathStar.setTroppers(Sets.newLinkedHashSet(trooper));
|
||||
Trooper trooper = new Trooper();
|
||||
trooper.setCode("TK-421");
|
||||
trooper.setDeathStar(deathStar);
|
||||
deathStar.setTroppers(Sets.newLinkedHashSet(trooper));
|
||||
|
||||
session.save(trooper);
|
||||
session.save(trooper);
|
||||
|
||||
transaction.commit();
|
||||
session.clear();
|
||||
transaction.commit();
|
||||
session.clear();
|
||||
|
||||
transaction = session.beginTransaction();
|
||||
deathStar = session.get(DeathStar.class, deathStar.getId());
|
||||
assertEquals(1, deathStar.getTroppers().size());
|
||||
assertNotNull(deathStar.getVader());
|
||||
transaction.commit();
|
||||
session.clear();
|
||||
transaction = session.beginTransaction();
|
||||
deathStar = session.get(DeathStar.class, deathStar.getId());
|
||||
assertEquals(1, deathStar.getTroppers().size());
|
||||
assertNotNull(deathStar.getVader());
|
||||
transaction.commit();
|
||||
session.clear();
|
||||
|
||||
transaction = session.beginTransaction();
|
||||
session.delete(deathStar);
|
||||
transaction.commit();
|
||||
session.clear();
|
||||
transaction = session.beginTransaction();
|
||||
session.delete(deathStar);
|
||||
transaction.commit();
|
||||
session.clear();
|
||||
|
||||
transaction = session.beginTransaction();
|
||||
transaction = session.beginTransaction();
|
||||
|
||||
//universe should not be deleted
|
||||
universe = session.get(Universe.class, universe.getId());
|
||||
assertNotNull(universe);
|
||||
//deathStar should be deleted
|
||||
deathStar = session.get(DeathStar.class, deathStar.getId());
|
||||
assertNull(deathStar);
|
||||
List universes = session.createSQLQuery("SELECT * from universe").list();
|
||||
List deathStars = session.createSQLQuery("SELECT * from deathstar").list();
|
||||
List troopers = session.createSQLQuery("SELECT * from trooper").list();
|
||||
List vaders = session.createSQLQuery("SELECT * from vader").list();
|
||||
//universe should not be deleted
|
||||
universe = session.get(Universe.class, universe.getId());
|
||||
assertNotNull(universe);
|
||||
//deathStar should be deleted
|
||||
deathStar = session.get(DeathStar.class, deathStar.getId());
|
||||
assertNull(deathStar);
|
||||
List universes = session.createSQLQuery("SELECT * from universe").list();
|
||||
List deathStars = session.createSQLQuery("SELECT * from deathstar").list();
|
||||
List troopers = session.createSQLQuery("SELECT * from trooper").list();
|
||||
List vaders = session.createSQLQuery("SELECT * from vader").list();
|
||||
|
||||
assertEquals(1, universes.size());
|
||||
assertEquals(1, deathStars.size());
|
||||
assertEquals(1, troopers.size());
|
||||
assertEquals(1, vaders.size());
|
||||
assertEquals(1, universes.size());
|
||||
assertEquals(1, deathStars.size());
|
||||
assertEquals(1, troopers.size());
|
||||
assertEquals(1, vaders.size());
|
||||
|
||||
//check if deleted is set
|
||||
assertTrue((Boolean)((Object[])deathStars.get(0))[1]);
|
||||
assertTrue((Boolean)((Object[])troopers.get(0))[1]);
|
||||
assertTrue((Boolean)((Object[])vaders.get(0))[1]);
|
||||
//universe should not be delted
|
||||
assertFalse((Boolean)((Object[])universes.get(0))[1]);
|
||||
//check if deleted is set
|
||||
assertTrue((Boolean)((Object[])deathStars.get(0))[1]);
|
||||
assertTrue((Boolean)((Object[])troopers.get(0))[1]);
|
||||
assertTrue((Boolean)((Object[])vaders.get(0))[1]);
|
||||
//universe should not be delted
|
||||
assertFalse((Boolean)((Object[])universes.get(0))[1]);
|
||||
|
||||
//check if references are kept
|
||||
assertNotNull(((Object[])deathStars.get(0))[2]);
|
||||
assertNotNull(((Object[])troopers.get(0))[3]);
|
||||
//check if references are kept
|
||||
assertNotNull(((Object[])deathStars.get(0))[2]);
|
||||
assertNotNull(((Object[])troopers.get(0))[3]);
|
||||
|
||||
session.close();
|
||||
session.close();
|
||||
|
||||
cleanupData();
|
||||
cleanupData();
|
||||
}
|
||||
|
||||
private void cleanupData() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
s.createSQLQuery("delete from trooper").executeUpdate();
|
||||
s.createSQLQuery("delete from deathstar").executeUpdate();
|
||||
s.createSQLQuery("delete from vader").executeUpdate();
|
||||
s.createSQLQuery("delete from universe").executeUpdate();
|
||||
});
|
||||
}
|
||||
private void cleanupData() {
|
||||
doInHibernate( this::sessionFactory, s -> {
|
||||
s.createSQLQuery("delete from trooper").executeUpdate();
|
||||
s.createSQLQuery("delete from deathstar").executeUpdate();
|
||||
s.createSQLQuery("delete from vader").executeUpdate();
|
||||
s.createSQLQuery("delete from universe").executeUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
BaseEntity.class,
|
||||
Universe.class,
|
||||
Universe.class,
|
||||
DeathStar.class,
|
||||
Vader.class,
|
||||
Trooper.class
|
||||
|
|
|
@ -12,14 +12,14 @@ import javax.persistence.OneToOne;
|
|||
@Where(clause = "deleted = false")
|
||||
public class Universe extends BaseEntity {
|
||||
|
||||
@OneToOne(optional = true, fetch = FetchType.EAGER, mappedBy = "universe")
|
||||
DeathStar deathStar;
|
||||
@OneToOne(optional = true, fetch = FetchType.EAGER, mappedBy = "universe")
|
||||
DeathStar deathStar;
|
||||
|
||||
public DeathStar getDeathStar() {
|
||||
return deathStar;
|
||||
}
|
||||
public DeathStar getDeathStar() {
|
||||
return deathStar;
|
||||
}
|
||||
|
||||
public void setDeathStar(DeathStar deathStar) {
|
||||
this.deathStar = deathStar;
|
||||
}
|
||||
public void setDeathStar(DeathStar deathStar) {
|
||||
this.deathStar = deathStar;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue