use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class FooBarTest method testOnCascadeDelete.
@Test
@RequiresDialectFeature(value = DialectChecks.SupportsCircularCascadeDeleteCheck.class, comment = "db/dialect does not support circular cascade delete constraints")
public void testOnCascadeDelete() throws Exception {
Session s = openSession();
s.beginTransaction();
Baz baz = new Baz();
baz.subs = new ArrayList();
Baz sub = new Baz();
sub.superBaz = baz;
baz.subs.add(sub);
s.save(baz);
s.flush();
assertTrue(s.createQuery("from Baz").list().size() == 2);
s.getTransaction().commit();
s.beginTransaction();
s.delete(baz);
s.getTransaction().commit();
s.beginTransaction();
assertTrue(s.createQuery("from Baz").list().size() == 0);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class PaginationTest method testLimitOffset.
@Test
@RequiresDialectFeature(value = DialectChecks.SupportLimitAndOffsetCheck.class, comment = "Dialect does not support limit+offset")
public void testLimitOffset() {
prepareTestData();
Session session = openSession();
session.beginTransaction();
List result;
result = generateBaseHQLQuery(session).setFirstResult(0).setMaxResults(20).list();
assertEquals(20, result.size());
assertEquals(0, ((DataPoint) result.get(0)).getSequence());
assertEquals(1, ((DataPoint) result.get(1)).getSequence());
result = generateBaseCriteria(session).setFirstResult(1).setMaxResults(20).list();
assertEquals(20, result.size());
assertEquals(1, ((DataPoint) result.get(0)).getSequence());
assertEquals(2, ((DataPoint) result.get(1)).getSequence());
result = generateBaseCriteria(session).setFirstResult(99).setMaxResults(Integer.MAX_VALUE - 200).list();
assertEquals(1, result.size());
assertEquals(99, ((DataPoint) result.get(0)).getSequence());
result = session.createQuery("select distinct description from DataPoint order by description").setFirstResult(2).setMaxResults(3).list();
assertEquals(3, result.size());
assertEquals("Description: 2", result.get(0));
assertEquals("Description: 3", result.get(1));
assertEquals("Description: 4", result.get(2));
result = session.createSQLQuery("select description, xval, yval from DataPoint order by xval, yval").setFirstResult(2).setMaxResults(5).list();
assertEquals(5, result.size());
Object[] row = (Object[]) result.get(0);
assertTrue(row[0] instanceof String);
result = session.createSQLQuery("select * from DataPoint order by xval, yval").setFirstResult(2).setMaxResults(5).list();
assertEquals(5, result.size());
session.getTransaction().commit();
session.close();
cleanupTestData();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testEntity.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public void testEntity() throws Exception {
Forest forest = new Forest();
forest.setName("Fontainebleau");
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
s.persist(forest);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
forest = (Forest) s.get(Forest.class, forest.getId());
assertNotNull(forest);
forest.setName("Fontainebleau");
//should not execute SQL update
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
forest = (Forest) s.get(Forest.class, forest.getId());
assertNotNull(forest);
forest.setLength(23);
//should execute dynamic SQL update
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
s.delete(s.get(Forest.class, forest.getId()));
tx.commit();
s.close();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testParameterizedType.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public void testParameterizedType() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
Forest f = new Forest();
f.setSmallText("ThisIsASmallText");
f.setBigText("ThisIsABigText");
s.persist(f);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Forest f2 = (Forest) s.get(Forest.class, f.getId());
assertEquals(f.getSmallText().toLowerCase(Locale.ROOT), f2.getSmallText());
assertEquals(f.getBigText().toUpperCase(Locale.ROOT), f2.getBigText());
tx.commit();
s.close();
}
use of org.hibernate.testing.RequiresDialectFeature in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testWhereClause.
@Test
@RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public void testWhereClause() throws Exception {
List<Doctor> doctors = new ArrayList<>();
Doctor goodDoctor = new Doctor();
goodDoctor.setName("goodDoctor");
goodDoctor.setYearsExperience(15);
goodDoctor.setActiveLicense(true);
doctors.add(goodDoctor);
Doctor docNotExperiencedLicensed = new Doctor();
docNotExperiencedLicensed.setName("docNotExperiencedLicensed");
docNotExperiencedLicensed.setYearsExperience(1);
docNotExperiencedLicensed.setActiveLicense(true);
doctors.add(docNotExperiencedLicensed);
Doctor docExperiencedUnlicensed = new Doctor();
docExperiencedUnlicensed.setName("docExperiencedNotlicensed");
docExperiencedUnlicensed.setYearsExperience(10);
doctors.add(docExperiencedUnlicensed);
Doctor badDoctor = new Doctor();
badDoctor.setName("badDoctor");
badDoctor.setYearsExperience(2);
doctors.add(badDoctor);
SoccerTeam team = new SoccerTeam();
team.setName("New team");
team.getPhysiologists().addAll(doctors);
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
for (Doctor doctor : doctors) {
s.persist(doctor);
}
s.persist(team);
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
Query<Doctor> query = s.createQuery("from " + Doctor.class.getName(), Doctor.class);
List<Doctor> list = query.getResultList();
assertEquals(2, list.size());
assertEquals(list.get(0).getName(), goodDoctor.getName());
assertEquals(list.get(1).getName(), docExperiencedUnlicensed.getName());
SoccerTeam loadedTeam = s.get(SoccerTeam.class, team.getId());
assertEquals(1, loadedTeam.getPhysiologists().size());
assertEquals(goodDoctor.getName(), loadedTeam.getPhysiologists().get(0).getName());
tx.commit();
s.close();
}
Aggregations