public void configure(Configuration cfg) { super.configure( cfg ); if ( Dialect.getDialect() instanceof OracleDialect ) { ( (RootClass) cfg.getClassMapping("org.hibernate.test.legacy.Foo") ).setForceDiscriminator(false); } }
public void testScrollableIterator() throws Exception { if ( getDialect() instanceof DB2Dialect || getDialect() instanceof OracleDialect || getDialect() instanceof SybaseDialect || getDialect() instanceof HSQLDialect ) { Session s = openSession(); Transaction txn = s.beginTransaction(); s.save( new Foo() ); s.save( new Foo() ); s.save( new Foo() ); s.save( new Bar() ); Query query = s.createQuery("select f, f.integer from Foo f"); assertTrue( query.getReturnTypes().length==2 ); ScrollableResults iter = query.scroll(); assertTrue( iter.next() ); assertTrue( iter.scroll(1) ); FooProxy f2 = (FooProxy) iter.get()[0]; assertTrue( f2!=null ); assertTrue( iter.scroll(-1) ); Object f1 = iter.get(0); iter.next(); assertTrue( f1!=null && iter.get(0)==f2 ); iter.getInteger(1); assertTrue( !iter.scroll(100) ); assertTrue( iter.first() ); assertTrue( iter.scroll(3) ); Object f4 = iter.get(0); assertTrue( f4!=null ); assertTrue( !iter.next() ); assertTrue( iter.first() ); assertTrue( iter.get(0)==f1 ); assertTrue( iter.last() ); assertTrue( iter.get(0)==f4 ); assertTrue( iter.previous() ); txn.commit(); s.close(); s = openSession(); txn = s.beginTransaction(); query = s.createQuery("select f, f.integer from Foo f"); assertTrue( query.getReturnTypes().length==2 ); iter = query.scroll(); assertTrue( iter.next() ); assertTrue( iter.scroll(1) ); f2 = (FooProxy) iter.get()[0]; assertTrue( f2!=null ); assertTrue( f2.getString()!=null && f2.getComponent().getImportantDates().length > 0 ); assertTrue( iter.scroll(-1) ); f1 = iter.get(0); iter.next(); assertTrue( f1!=null && iter.get(0)==f2 ); iter.getInteger(1); assertTrue( !iter.scroll(100) ); assertTrue( iter.first() ); assertTrue( iter.scroll(3) ); f4 = iter.get(0); assertTrue( f4!=null ); assertTrue( !iter.next() ); assertTrue( iter.first() ); assertTrue( iter.get(0)==f1 ); assertTrue( iter.last() ); assertTrue( iter.get(0)==f4 ); assertTrue( iter.previous() ); assertTrue( s.delete("from Foo")==4 ); s.flush(); assertTrue( s.find("from java.lang.Object").size()==0 ); txn.commit(); s.close(); } }
public void testFormulaDiscriminator() throws Exception { if ( ( getDialect() instanceof OracleDialect ) || ( getDialect() instanceof HSQLDialect ) ) return; Session s = getSessions().openSession(); I i = new I(); i.setName( "i" ); i.setType( 'a' ); J j = new J(); j.setName( "j" ); j.setType( 'x' ); j.setAmount( 1.0f ); Serializable iid = s.save(i); Serializable jid = s.save(j); s.flush(); s.connection().commit(); s.close(); getSessions().evict(I.class); s = getSessions().openSession(); j = (J) s.get(I.class, jid); i = (I) s.get(I.class, iid); assertTrue( i.getClass()==I.class ); j.setAmount( 0.5f ); s.lock(i, LockMode.UPGRADE); s.flush(); s.connection().commit(); s.close(); s = getSessions().openSession(); j = (J) s.get(I.class, jid, LockMode.UPGRADE); i = (I) s.get(I.class, iid, LockMode.UPGRADE); s.flush(); s.connection().commit(); s.close(); s = getSessions().openSession(); assertTrue( s.find("from I").size()==2 ); assertTrue( s.find("from J").size()==1 ); assertTrue( s.find("from I i where i.class = 0").size()==1 ); assertTrue( s.find("from I i where i.class = 1").size()==1 ); s.connection().commit(); s.close(); s = getSessions().openSession(); j = (J) s.get(J.class, jid); i = (I) s.get(I.class, iid); s.delete(j); s.delete(i); s.flush(); s.connection().commit(); s.close(); }
public void testFindBySQLAssociatedObjects() throws HibernateException, SQLException { Session s = openSession(); s.delete("from Assignable"); s.delete("from Category"); Category c = new Category(); c.setName("NAME"); Assignable assn = new Assignable(); assn.setId("i.d."); List l = new ArrayList(); l.add(c); assn.setCategories(l); c.setAssignable(assn); s.save(assn); s.flush(); s.connection().commit(); s.close(); s = openSession(); List list = s.createSQLQuery("select {category.*} from category {category}", "category", Category.class).list(); list.get(0); s.connection().commit(); s.close(); if ( getDialect() instanceof MySQLDialect ) return; if ( getDialect() instanceof OracleDialect ) return; // todo : this fails on Oracle8 also s = openSession(); Query query = s.getNamedQuery("namedsql"); assertNotNull(query); list = query.list(); assertNotNull(list); Object[] values = (Object[]) list.get(0); assertNotNull(values[0]); assertNotNull(values[1]); assertTrue("wrong type: " + values[0].getClass(), values[0] instanceof Category); assertTrue("wrong type: " + values[1].getClass(), values[1] instanceof Assignable); s.connection().commit(); s.close(); }