Search in sources :

Example 1 with Product

use of org.hibernate.test.cid.Product in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testStandardFunctions.

@Test
public void testStandardFunctions() throws Exception {
    Session session = openSession();
    Transaction t = session.beginTransaction();
    Product p = new Product();
    p.setDescription("a product");
    p.setPrice(new BigDecimal(1.0));
    p.setProductId("abc123");
    session.persist(p);
    Object[] result = (Object[]) session.createQuery("select current_time(), current_date(), current_timestamp() from Product").uniqueResult();
    assertTrue(result[0] instanceof Time);
    assertTrue(result[1] instanceof Date);
    assertTrue(result[2] instanceof Timestamp);
    assertNotNull(result[0]);
    assertNotNull(result[1]);
    assertNotNull(result[2]);
    session.delete(p);
    t.commit();
    session.close();
}
Also used : Transaction(org.hibernate.Transaction) Product(org.hibernate.test.cid.Product) Time(java.sql.Time) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal) Date(java.sql.Date) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with Product

use of org.hibernate.test.cid.Product in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testRowValueConstructorSyntaxInInList.

@Test
public void testRowValueConstructorSyntaxInInList() {
    Session s = openSession();
    s.beginTransaction();
    Product product = new Product();
    product.setDescription("My Product");
    product.setNumberAvailable(10);
    product.setPrice(new BigDecimal(123));
    product.setProductId("4321");
    s.save(product);
    Customer customer = new Customer();
    customer.setCustomerId("123456789");
    customer.setName("My customer");
    customer.setAddress("somewhere");
    s.save(customer);
    Order order = customer.generateNewOrder(new BigDecimal(1234));
    s.save(order);
    LineItem li = order.generateLineItem(product, 5);
    s.save(li);
    product = new Product();
    product.setDescription("My Product");
    product.setNumberAvailable(10);
    product.setPrice(new BigDecimal(123));
    product.setProductId("1234");
    s.save(product);
    li = order.generateLineItem(product, 10);
    s.save(li);
    s.flush();
    Query query = s.createQuery("from LineItem l where l.id in (:idList)");
    List<Id> list = new ArrayList<Id>();
    list.add(new Id("123456789", order.getId().getOrderNumber(), "4321"));
    list.add(new Id("123456789", order.getId().getOrderNumber(), "1234"));
    query.setParameterList("idList", list);
    assertEquals(2, query.list().size());
    query = s.createQuery("from LineItem l where l.id in :idList");
    query.setParameterList("idList", list);
    assertEquals(2, query.list().size());
    s.getTransaction().rollback();
    s.close();
}
Also used : Order(org.hibernate.test.cid.Order) Query(org.hibernate.Query) Customer(org.hibernate.test.cid.Customer) ArrayList(java.util.ArrayList) Product(org.hibernate.test.cid.Product) LineItem(org.hibernate.test.cid.LineItem) Id(org.hibernate.test.cid.LineItem.Id) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session) Test(org.junit.Test)

Example 3 with Product

use of org.hibernate.test.cid.Product in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testOneToManyFilter.

@Test
@SkipForDialect(value = IngresDialect.class, jiraKey = "HHH-4976", comment = "Ingres 9.3 does not support sub-selects in the select list")
public void testOneToManyFilter() throws Throwable {
    Session session = openSession();
    Transaction txn = session.beginTransaction();
    Product product = new Product();
    product.setDescription("My Product");
    product.setNumberAvailable(10);
    product.setPrice(new BigDecimal(123));
    product.setProductId("4321");
    session.save(product);
    Customer customer = new Customer();
    customer.setCustomerId("123456789");
    customer.setName("My customer");
    customer.setAddress("somewhere");
    session.save(customer);
    Order order = customer.generateNewOrder(new BigDecimal(1234));
    session.save(order);
    LineItem li = order.generateLineItem(product, 5);
    session.save(li);
    session.flush();
    assertEquals(session.createFilter(customer.getOrders(), "").list().size(), 1);
    assertEquals(session.createFilter(order.getLineItems(), "").list().size(), 1);
    assertEquals(session.createFilter(order.getLineItems(), "where this.quantity > :quantity").setInteger("quantity", 5).list().size(), 0);
    session.delete(li);
    session.delete(order);
    session.delete(product);
    session.delete(customer);
    txn.commit();
    session.close();
}
Also used : Order(org.hibernate.test.cid.Order) Transaction(org.hibernate.Transaction) Customer(org.hibernate.test.cid.Customer) Product(org.hibernate.test.cid.Product) LineItem(org.hibernate.test.cid.LineItem) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 4 with Product

use of org.hibernate.test.cid.Product in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testImplicitPolymorphism.

@Test
@SkipForDialect(value = IngresDialect.class, jiraKey = "HHH-4976", comment = "Ingres 9.3 does not support sub-selects in the select list")
public void testImplicitPolymorphism() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Product product = new Product();
    product.setDescription("My Product");
    product.setNumberAvailable(10);
    product.setPrice(new BigDecimal(123));
    product.setProductId("4321");
    s.save(product);
    List list = s.createQuery("from java.lang.Comparable").list();
    assertEquals(list.size(), 0);
    list = s.createQuery("from java.lang.Object").list();
    assertEquals(list.size(), 1);
    s.delete(product);
    list = s.createQuery("from java.lang.Object").list();
    assertEquals(list.size(), 0);
    t.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Product(org.hibernate.test.cid.Product) List(java.util.List) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Aggregations

BigDecimal (java.math.BigDecimal)4 Session (org.hibernate.Session)4 Product (org.hibernate.test.cid.Product)4 Test (org.junit.Test)4 Transaction (org.hibernate.Transaction)3 ArrayList (java.util.ArrayList)2 Customer (org.hibernate.test.cid.Customer)2 LineItem (org.hibernate.test.cid.LineItem)2 Order (org.hibernate.test.cid.Order)2 SkipForDialect (org.hibernate.testing.SkipForDialect)2 Date (java.sql.Date)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Query (org.hibernate.Query)1 Id (org.hibernate.test.cid.LineItem.Id)1