use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class IndexedCollectionTest method testComponentSubPropertyMapKey.
@Test
@RequiresDialect({ HSQLDialect.class, H2Dialect.class })
public void testComponentSubPropertyMapKey() throws Exception {
Session s;
Transaction tx;
s = openSession();
tx = s.beginTransaction();
AddressBook book = new AddressBook();
book.setOwner("Emmanuel");
AddressEntryPk helene = new AddressEntryPk("Helene", "Michau");
AddressEntry heleneEntry = new AddressEntry();
heleneEntry.setBook(book);
heleneEntry.setCity("Levallois");
heleneEntry.setStreet("Louis Blanc");
heleneEntry.setPerson(helene);
AddressEntryPk primeMinister = new AddressEntryPk("Dominique", "Villepin");
AddressEntry primeMinisterEntry = new AddressEntry();
primeMinisterEntry.setBook(book);
primeMinisterEntry.setCity("Paris");
primeMinisterEntry.setStreet("Hotel Matignon");
primeMinisterEntry.setPerson(primeMinister);
book.getEntries().put(helene, heleneEntry);
book.getEntries().put(primeMinister, primeMinisterEntry);
s.persist(book);
s.flush();
s.clear();
book = (AddressBook) s.get(AddressBook.class, book.getId());
assertEquals(2, book.getLastNameEntries().size());
assertEquals(heleneEntry.getCity(), book.getLastNameEntries().get("Michau").getCity());
AddressEntryPk fake = new AddressEntryPk("Fake", "Fake");
book.getEntries().put(fake, primeMinisterEntry);
s.flush();
s.clear();
book = (AddressBook) s.get(AddressBook.class, book.getId());
assertEquals(2, book.getEntries().size());
assertNull(book.getEntries().get(fake));
s.delete(book);
tx.rollback();
s.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class OrderByTest method testOrderByReferencingFormulaColumn.
@Test
@TestForIssue(jiraKey = "HHH-7608")
@RequiresDialect({ H2Dialect.class, Oracle8iDialect.class })
public void testOrderByReferencingFormulaColumn() {
Session session = openSession();
// Populating database with test data.
session.getTransaction().begin();
Box box1 = new Box(1);
Item item1 = new Item(1, "1", box1);
Item item2 = new Item(2, "22", box1);
Item item3 = new Item(3, "2", box1);
session.persist(box1);
session.persist(item1);
session.persist(item2);
session.persist(item3);
session.flush();
session.refresh(item1);
session.refresh(item2);
session.refresh(item3);
session.getTransaction().commit();
session.clear();
session.getTransaction().begin();
box1 = (Box) session.get(Box.class, box1.getId());
Assert.assertEquals(Arrays.asList(item2, item1, item3), box1.getItems());
session.getTransaction().commit();
session.clear();
// Cleanup data.
session.getTransaction().begin();
session.delete(item1);
session.delete(item2);
session.delete(item3);
session.delete(box1);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class OrderByTest method testHqlNullsFirstLast.
@Test
@TestForIssue(jiraKey = "HHH-465")
@RequiresDialect(value = { H2Dialect.class, MySQLDialect.class, SQLServer2008Dialect.class }, comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression. " + "For MySQL and SQL Server 2008 testing overridden Dialect#renderOrderByElement(String, String, String, NullPrecedence) method. " + "MySQL and SQL Server 2008 does not support NULLS FIRST / LAST syntax at the moment, so transforming the expression to 'CASE WHEN ...'.")
public void testHqlNullsFirstLast() {
Session session = openSession();
// Populating database with test data.
session.getTransaction().begin();
Zoo zoo1 = new Zoo();
zoo1.setName(null);
Zoo zoo2 = new Zoo();
zoo2.setName("Warsaw ZOO");
session.persist(zoo1);
session.persist(zoo2);
session.getTransaction().commit();
session.getTransaction().begin();
List<Zoo> orderedResults = (List<Zoo>) session.createQuery("from Zoo z order by z.name nulls lAsT").list();
Assert.assertEquals(Arrays.asList(zoo2, zoo1), orderedResults);
session.getTransaction().commit();
session.clear();
// Cleanup data.
session.getTransaction().begin();
session.delete(zoo1);
session.delete(zoo2);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class OrderByTest method testAnnotationNullsFirstLast.
@Test
@TestForIssue(jiraKey = "HHH-465")
@RequiresDialect(value = { H2Dialect.class, MySQLDialect.class, SQLServer2008Dialect.class }, comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression. " + "For MySQL and SQL Server 2008 testing overridden Dialect#renderOrderByElement(String, String, String, NullPrecedence) method. " + "MySQL and SQLServer 2008 does not support NULLS FIRST / LAST syntax at the moment, so transforming the expression to 'CASE WHEN ...'.")
public void testAnnotationNullsFirstLast() {
Session session = openSession();
// Populating database with test data.
session.getTransaction().begin();
Tiger tiger1 = new Tiger();
// Explicitly setting null value.
tiger1.setName(null);
Tiger tiger2 = new Tiger();
tiger2.setName("Max");
Monkey monkey1 = new Monkey();
monkey1.setName("Michael");
Monkey monkey2 = new Monkey();
// Explicitly setting null value.
monkey2.setName(null);
Zoo zoo = new Zoo("Warsaw ZOO");
zoo.getTigers().add(tiger1);
zoo.getTigers().add(tiger2);
zoo.getMonkeys().add(monkey1);
zoo.getMonkeys().add(monkey2);
session.persist(zoo);
session.persist(tiger1);
session.persist(tiger2);
session.persist(monkey1);
session.persist(monkey2);
session.getTransaction().commit();
session.clear();
session.getTransaction().begin();
zoo = (Zoo) session.get(Zoo.class, zoo.getId());
// Testing @org.hibernate.annotations.OrderBy.
Iterator<Tiger> iterator1 = zoo.getTigers().iterator();
Assert.assertEquals(tiger2.getName(), iterator1.next().getName());
Assert.assertNull(iterator1.next().getName());
// Testing @javax.persistence.OrderBy.
Iterator<Monkey> iterator2 = zoo.getMonkeys().iterator();
Assert.assertEquals(monkey1.getName(), iterator2.next().getName());
Assert.assertNull(iterator2.next().getName());
session.getTransaction().commit();
session.clear();
// Cleanup data.
session.getTransaction().begin();
session.delete(tiger1);
session.delete(tiger2);
session.delete(monkey1);
session.delete(monkey2);
session.delete(zoo);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testEmptyInList.
@Test
@TestForIssue(jiraKey = "HHH-2045")
@RequiresDialect(H2Dialect.class)
public void testEmptyInList() {
Session session = openSession();
session.beginTransaction();
Human human = new Human();
human.setName(new Name("Lukasz", null, "Antoniak"));
human.setNickName("NONE");
session.save(human);
session.getTransaction().commit();
session.close();
session = openSession();
session.beginTransaction();
List results = session.createQuery("from Human h where h.nickName in ()").list();
assertEquals(0, results.size());
session.getTransaction().commit();
session.close();
session = openSession();
session.beginTransaction();
session.delete(human);
session.getTransaction().commit();
session.close();
}
Aggregations