use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.
the class HQLScrollFetchTest method testIncompleteScrollSecondResultInTransaction.
@Test
@TestForIssue(jiraKey = "HHH-1283")
public void testIncompleteScrollSecondResultInTransaction() {
Session s = openSession();
Transaction tx = s.beginTransaction();
ScrollableResults results = s.createQuery(QUERY + " order by p.name asc").scroll();
results.next();
Parent p = (Parent) results.get(0);
assertResultFromOneUser(p);
results.next();
p = (Parent) results.get(0);
assertResultFromOneUser(p);
tx.commit();
s.close();
}
use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.
the class HQLScrollFetchTest method testIncompleteScrollLast.
@Test
@TestForIssue(jiraKey = "HHH-1283")
public void testIncompleteScrollLast() {
Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery(QUERY + " order by p.name asc").scroll();
results.next();
Parent p = (Parent) results.get(0);
assertResultFromOneUser(p);
results.last();
// get the other parent entity from the persistence context.
// since the result set was scrolled to the end, the other parent entity's collection has been
// properly initialized.
Parent pOther = null;
Set childrenOther = new HashSet();
for (Object entity : ((SessionImplementor) s).getPersistenceContext().getEntitiesByKey().values()) {
if (Parent.class.isInstance(entity)) {
if (entity != p) {
if (pOther != null) {
fail("unexpected parent found.");
}
pOther = (Parent) entity;
}
} else if (Child.class.isInstance(entity)) {
if (!p.getChildren().contains(entity)) {
childrenOther.add(entity);
}
} else {
fail("unexpected type of entity.");
}
}
// check that the same second parent is obtained by calling Session.get()
assertNotNull(pOther);
assertSame(pOther, s.get(Parent.class, pOther.getId()));
// access pOther's collection; should be completely loaded
assertTrue(Hibernate.isInitialized(pOther.getChildren()));
assertEquals(childrenOther, pOther.getChildren());
assertResultFromOneUser(pOther);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.
the class HQLScrollFetchTest method testIncompleteScrollFirstResultInTransaction.
@Test
public void testIncompleteScrollFirstResultInTransaction() {
Session s = openSession();
Transaction tx = s.beginTransaction();
ScrollableResults results = s.createQuery(QUERY + " order by p.name asc").scroll();
results.next();
Parent p = (Parent) results.get(0);
assertResultFromOneUser(p);
tx.commit();
s.close();
}
use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.
the class ScrollableCollectionFetchingTest method testScrollingJoinFetchesPositioning.
@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with" + "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
@SkipForDialect(value = AbstractHANADialect.class, comment = "HANA only supports forward-only cursors.")
public void testScrollingJoinFetchesPositioning() {
TestData data = new TestData();
data.prepare();
Session s = openSession();
Transaction txn = s.beginTransaction();
ScrollableResults results = s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").scroll();
results.first();
Animal animal = (Animal) results.get(0);
assertEquals("first() did not return expected row", data.root1Id, animal.getId());
results.scroll(1);
animal = (Animal) results.get(0);
assertEquals("scroll(1) did not return expected row", data.root2Id, animal.getId());
results.scroll(-1);
animal = (Animal) results.get(0);
assertEquals("scroll(-1) did not return expected row", data.root1Id, animal.getId());
results.setRowNumber(1);
animal = (Animal) results.get(0);
assertEquals("setRowNumber(1) did not return expected row", data.root1Id, animal.getId());
results.setRowNumber(2);
animal = (Animal) results.get(0);
assertEquals("setRowNumber(2) did not return expected row", data.root2Id, animal.getId());
txn.commit();
s.close();
data.cleanup();
}
use of org.hibernate.ScrollableResults in project hibernate-orm by hibernate.
the class ScrollableCollectionFetchingTest method testScrollingJoinFetchesSingleRowResultSet.
@Test
@SkipForDialect(value = CUBRIDDialect.class, comment = "As of verion 8.4.1 CUBRID doesn't support temporary tables. This test fails with" + "HibernateException: cannot doAfterTransactionCompletion multi-table deletes using dialect not supporting temp tables")
@SkipForDialect(value = AbstractHANADialect.class, comment = "HANA only supports forward-only cursors")
public void testScrollingJoinFetchesSingleRowResultSet() {
Session s = openSession();
Transaction txn = s.beginTransaction();
Animal mother = new Animal();
mother.setDescription("root-1");
Animal daughter = new Animal();
daughter.setDescription("daughter");
daughter.setMother(mother);
mother.addOffspring(daughter);
s.save(mother);
s.save(daughter);
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
assertNotNull(s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").uniqueResult());
ScrollableResults results = s.createQuery("from Animal a left join fetch a.offspring where a.description like :desc order by a.id").setString("desc", "root%").scroll();
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.previous());
assertTrue(results.next());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.next());
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertTrue(results.previous());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.previous());
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertTrue(results.next());
assertTrue(results.isFirst());
assertTrue(results.isLast());
results.beforeFirst();
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.previous());
assertTrue(results.first());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.next());
results.afterLast();
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.next());
assertTrue(results.last());
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.next());
assertTrue(results.first());
assertTrue(results.isFirst());
assertTrue(results.isLast());
for (int i = 1; i < 3; i++) {
assertTrue(results.setRowNumber(1));
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.scroll(i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertTrue(results.setRowNumber(1));
assertTrue(results.isFirst());
assertTrue(results.isLast());
assertFalse(results.scroll(-i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
if (i != 1) {
assertFalse(results.setRowNumber(i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
assertFalse(results.setRowNumber(-i));
assertFalse(results.isFirst());
assertFalse(results.isLast());
}
}
txn.commit();
s.close();
s = openSession();
txn = s.beginTransaction();
s.createQuery("delete Animal where not description like 'root%'").executeUpdate();
s.createQuery("delete Animal").executeUpdate();
txn.commit();
s.close();
}
Aggregations