use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class InheritedEntityGraphTest method singleAttributeNodeInheritanceTest.
@Test
@TestForIssue(jiraKey = "HHH-10261")
public void singleAttributeNodeInheritanceTest() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Bar bar = new Bar();
em.persist(bar);
Foo foo = new Foo();
foo.bar = bar;
em.persist(foo);
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
EntityGraph<Foo> entityGraph = em.createEntityGraph(Foo.class);
entityGraph.addSubgraph("bar");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("javax.persistence.loadgraph", entityGraph);
Foo result = em.find(Foo.class, foo.id, properties);
assertTrue(Hibernate.isInitialized(result));
assertTrue(Hibernate.isInitialized(result.bar));
em.getTransaction().commit();
em.close();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class OneToOneOrphanTest method testFlushTransientOneToOneNoCascade.
@Test
@TestForIssue(jiraKey = "HHH-9568")
public void testFlushTransientOneToOneNoCascade() throws Exception {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
B b = new B();
A a = new A();
a.setB(b);
try {
em.persist(a);
em.flush();
em.getTransaction().commit();
fail("should have raised an IllegalStateException");
} catch (IllegalStateException ex) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
// IllegalStateException caught as expected
} finally {
em.close();
}
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class DeleteMultiLevelOrphansTest method testDirectAndNestedAssociationsOrphanedWhileManaged.
@Test
@TestForIssue(jiraKey = "HHH-9091")
public void testDirectAndNestedAssociationsOrphanedWhileManaged() {
createData();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
List results = em.createQuery("from Tranchenmodell").getResultList();
assertEquals(1, results.size());
results = em.createQuery("from Preisregelung").getResultList();
assertEquals(1, results.size());
Preisregelung preisregelung = (Preisregelung) results.get(0);
Tranchenmodell tranchenmodell = preisregelung.getTranchenmodell();
assertNotNull(tranchenmodell);
assertNotNull(tranchenmodell.getX());
assertEquals(2, tranchenmodell.getTranchen().size());
assertNotNull(tranchenmodell.getTranchen().get(0).getY());
preisregelung.setTranchenmodell(null);
tranchenmodell.setX(null);
tranchenmodell.getTranchen().get(0).setY(null);
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
preisregelung = (Preisregelung) em.find(Preisregelung.class, preisregelung.getId());
assertNull(preisregelung.getTranchenmodell());
results = em.createQuery("from Tranchenmodell").getResultList();
assertEquals(0, results.size());
results = em.createQuery("from Tranche").getResultList();
assertEquals(0, results.size());
results = em.createQuery("from X").getResultList();
assertEquals(0, results.size());
results = em.createQuery("from Y").getResultList();
assertEquals(0, results.size());
results = em.createQuery("from Preisregelung").getResultList();
assertEquals(1, results.size());
em.getTransaction().commit();
em.close();
cleanupData();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class DeleteMultiLevelOrphansTest method testReplacedDirectAssociationWhileManaged.
@Test
@TestForIssue(jiraKey = "HHH-9091")
public void testReplacedDirectAssociationWhileManaged() {
createData();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
List results = em.createQuery("from Tranchenmodell").getResultList();
assertEquals(1, results.size());
results = em.createQuery("from Preisregelung").getResultList();
assertEquals(1, results.size());
Preisregelung preisregelung = (Preisregelung) results.get(0);
Tranchenmodell tranchenmodell = preisregelung.getTranchenmodell();
assertNotNull(tranchenmodell);
assertNotNull(tranchenmodell.getX());
assertEquals(2, tranchenmodell.getTranchen().size());
assertNotNull(tranchenmodell.getTranchen().get(0).getY());
// Create a new Tranchenmodell with new direct and nested associations
Tranchenmodell tranchenmodellNew = new Tranchenmodell();
X xNew = new X();
tranchenmodellNew.setX(xNew);
xNew.setTranchenmodell(tranchenmodellNew);
Tranche trancheNew = new Tranche();
tranchenmodellNew.getTranchen().add(trancheNew);
trancheNew.setTranchenmodell(tranchenmodellNew);
Y yNew = new Y();
trancheNew.setY(yNew);
yNew.setTranche(trancheNew);
// Replace with a new Tranchenmodell instance containing new direct and nested associations
preisregelung.setTranchenmodell(tranchenmodellNew);
tranchenmodellNew.setPreisregelung(preisregelung);
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
results = em.createQuery("from Tranche").getResultList();
assertEquals(1, results.size());
results = em.createQuery("from Tranchenmodell").getResultList();
assertEquals(1, results.size());
results = em.createQuery("from X").getResultList();
assertEquals(1, results.size());
results = em.createQuery("from Y").getResultList();
assertEquals(1, results.size());
results = em.createQuery("from Preisregelung").getResultList();
assertEquals(1, results.size());
preisregelung = (Preisregelung) results.get(0);
tranchenmodell = preisregelung.getTranchenmodell();
assertNotNull(tranchenmodell);
assertEquals(tranchenmodellNew.getId(), tranchenmodell.getId());
assertNotNull(tranchenmodell.getX());
assertEquals(xNew.getId(), tranchenmodell.getX().getId());
assertEquals(1, tranchenmodell.getTranchen().size());
assertEquals(trancheNew.getId(), tranchenmodell.getTranchen().get(0).getId());
assertEquals(yNew.getId(), tranchenmodell.getTranchen().get(0).getY().getId());
// Replace with a new Tranchenmodell instance with no associations
tranchenmodellNew = new Tranchenmodell();
preisregelung.setTranchenmodell(tranchenmodellNew);
tranchenmodellNew.setPreisregelung(preisregelung);
em.getTransaction().commit();
em.close();
em = getOrCreateEntityManager();
em.getTransaction().begin();
results = em.createQuery("from Tranchenmodell").getResultList();
assertEquals(1, results.size());
tranchenmodell = (Tranchenmodell) results.get(0);
assertEquals(tranchenmodellNew.getId(), tranchenmodell.getId());
results = em.createQuery("from Preisregelung").getResultList();
assertEquals(1, results.size());
preisregelung = (Preisregelung) results.get(0);
assertEquals(tranchenmodell, preisregelung.getTranchenmodell());
results = em.createQuery("from Tranche").getResultList();
assertEquals(0, results.size());
results = em.createQuery("from X").getResultList();
assertEquals(0, results.size());
results = em.createQuery("from Y").getResultList();
assertEquals(0, results.size());
em.getTransaction().commit();
em.close();
cleanupData();
}
use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class JarVisitorTest method testGetBytesFromInputStream.
@Test
@TestForIssue(jiraKey = "HHH-7835")
public void testGetBytesFromInputStream() throws Exception {
File file = buildLargeJar();
long start = System.currentTimeMillis();
InputStream stream = new BufferedInputStream(new FileInputStream(file));
int oldLength = getBytesFromInputStream(stream).length;
stream.close();
long oldTime = System.currentTimeMillis() - start;
start = System.currentTimeMillis();
stream = new BufferedInputStream(new FileInputStream(file));
int newLength = ArchiveHelper.getBytesFromInputStream(stream).length;
stream.close();
long newTime = System.currentTimeMillis() - start;
assertEquals(oldLength, newLength);
assertTrue(oldTime > newTime);
}
Aggregations