use of com.vladmihalcea.hibernate.model.bag.Parent in project vladmihalcea.wordpress.com by vladmihalcea.
the class HibernateBagDuplicateTest method test.
@Test
public void test() {
final Long parentId = cleanAndSaveParent();
Parent parent = transactionTemplate.execute(new TransactionCallback<Parent>() {
@Override
public Parent doInTransaction(TransactionStatus transactionStatus) {
Parent parent = loadParent(parentId);
Child child1 = new Child();
child1.setName("child1");
Child child2 = new Child();
child2.setName("child2");
parent.addChild(child1);
parent.addChild(child2);
entityManager.merge(parent);
entityManager.flush();
if (parent.getChildren().size() == 4) {
LOG.error("Duplicates rows generated!");
}
return parent;
}
});
//assertEquals(2, parent.getChildren().size());
if (parent.getChildren().size() == 4) {
LOG.error("Duplicates rows generated!");
}
transactionTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus transactionStatus) {
assertEquals(4, loadParent(parentId).getChildren().size());
return null;
}
});
}
use of com.vladmihalcea.hibernate.model.bag.Parent in project vladmihalcea.wordpress.com by vladmihalcea.
the class HibernateBagDuplicateTest method testFixByPersistingChild.
@Test
public void testFixByPersistingChild() {
final Long parentId = cleanAndSaveParent();
Parent parent = transactionTemplate.execute(new TransactionCallback<Parent>() {
@Override
public Parent doInTransaction(TransactionStatus transactionStatus) {
Parent parent = loadParent(parentId);
Child child1 = new Child();
child1.setName("child1");
Child child2 = new Child();
child2.setName("child2");
entityManager.persist(child1);
entityManager.persist(child2);
parent.addChild(child1);
parent.addChild(child2);
entityManager.merge(parent);
parent.getChildren().size();
return parent;
}
});
assertEquals(2, parent.getChildren().size());
}
Aggregations