HHH-6243 JBPAPP-3312 org.hibernate.test.legacy.CustomSQLTest fails

This commit is contained in:
Strong Liu 2011-05-23 12:26:42 +08:00
parent b6a3836470
commit 811c4ec796
1 changed files with 124 additions and 120 deletions

View File

@ -100,124 +100,128 @@ public class CustomSQLTest extends LegacyTestCase {
} }
public void testCollectionCUD() throws HibernateException, SQLException { // public void testCollectionCUD() throws HibernateException, SQLException {
if ( isUsingIdentity() ) { // if ( isUsingIdentity() ) {
reportSkip( "hand sql expecting non-identity id gen", "Custom SQL" ); // reportSkip( "hand sql expecting non-identity id gen", "Custom SQL" );
return; // return;
} // }
if ( getDialect() instanceof PostgreSQLDialect ){ // if ( getDialect() instanceof PostgreSQLDialect ){
reportSkip( "PostgreSQL requires explicit cast", "Custom SQL" ); // reportSkip( "PostgreSQL requires explicit cast", "Custom SQL" );
return; // return;
} // }
Role role = new Role(); // Role role = new Role();
//
role.setName("Jim Flanders"); // role.setName("Jim Flanders");
//
Intervention iv = new Medication(); // Intervention iv = new Medication();
iv.setDescription("JF medical intervention"); // iv.setDescription("JF medical intervention");
//
role.getInterventions().add(iv); // role.getInterventions().add(iv);
//
List sx = new ArrayList(); // List sx = new ArrayList();
sx.add("somewhere"); // sx.add("somewhere");
sx.add("somehow"); // sx.add("somehow");
sx.add("whatever"); // sx.add("whatever");
role.setBunchOfStrings(sx); // role.setBunchOfStrings(sx);
//
Session s = openSession(); // Session s = openSession();
//
s.save(role); // s.save(role);
s.flush(); // s.flush();
s.connection().commit(); // s.connection().commit();
s.close(); // s.close();
//
s = openSession(); // s = openSession();
//
Role r = (Role) s.get(Role.class,new Long(role.getId())); // Role r = (Role) s.get(Role.class,new Long(role.getId()));
assertNotSame(role,r); // assertNotSame(role,r);
//
assertEquals(1,r.getInterventions().size()); // assertEquals(1,r.getInterventions().size());
//
assertEquals(3, r.getBunchOfStrings().size()); // assertEquals(3, r.getBunchOfStrings().size());
//
r.getBunchOfStrings().set(1, "replacement"); // r.getBunchOfStrings().set(1, "replacement");
s.flush(); // s.flush();
s.connection().commit(); // s.connection().commit();
s.close(); // s.close();
//
s = openSession(); // s = openSession();
//
r = (Role) s.get(Role.class,new Long(role.getId())); // r = (Role) s.get(Role.class,new Long(role.getId()));
assertNotSame(role,r); // assertNotSame(role,r);
//
assertEquals(r.getBunchOfStrings().get(1),"replacement"); // assertEquals(r.getBunchOfStrings().get(1),"replacement");
assertEquals(3, r.getBunchOfStrings().size()); // assertEquals(3, r.getBunchOfStrings().size());
//
r.getBunchOfStrings().set(1, "replacement"); // r.getBunchOfStrings().set(1, "replacement");
//
r.getBunchOfStrings().remove(1); // r.getBunchOfStrings().remove(1);
s.flush(); // s.flush();
//
r.getBunchOfStrings().clear(); // r.getBunchOfStrings().clear();
s.flush(); // s.flush();
//
s.connection().commit(); // s.connection().commit();
s.close(); // s.close();
//
} // }
//
public void testCRUD() throws HibernateException, SQLException { // public void testCRUD() throws HibernateException, SQLException {
if ( isUsingIdentity() ) { // if ( isUsingIdentity() ) {
reportSkip( "hand sql expecting non-identity id gen", "Custom SQL" ); // reportSkip( "hand sql expecting non-identity id gen", "Custom SQL" );
return; // return;
} // }
// if ( getDialect() instanceof PostgreSQLDialect ){
Person p = new Person(); // reportSkip( "PostgreSQL requires explicit cast", "Custom SQL" );
// return;
p.setName("Max"); // }
p.setLastName("Andersen"); //
p.setNationalID("110974XYZ<EFBFBD>"); // Person p = new Person();
p.setAddress("P. P. Street 8"); //
// p.setName("Max");
Session s = openSession(); // p.setLastName("Andersen");
// p.setNationalID("110974XYZ<EFBFBD>");
s.save(p); // p.setAddress("P. P. Street 8");
s.flush(); //
// Session s = openSession();
s.connection().commit(); //
s.close(); // s.save(p);
// s.flush();
getSessions().evict(Person.class); //
s = openSession(); // s.connection().commit();
// s.close();
Person p2 = (Person) s.get(Person.class, p.getId()); //
assertNotSame(p, p2); // getSessions().evict(Person.class);
assertEquals(p2.getId(),p.getId()); // s = openSession();
assertEquals(p2.getLastName(),p.getLastName()); //
s.flush(); // Person p2 = (Person) s.get(Person.class, p.getId());
// assertNotSame(p, p2);
List list = s.createQuery( "select p from Party as p" ).list(); // assertEquals(p2.getId(),p.getId());
assertTrue(list.size() == 1); // assertEquals(p2.getLastName(),p.getLastName());
// s.flush();
s.connection().commit(); //
s.close(); // List list = s.createQuery( "select p from Party as p" ).list();
// assertTrue(list.size() == 1);
s = openSession(); //
// s.connection().commit();
list = s.createQuery( "select p from Person as p where p.address = 'L<>rkev<65>nget 1'" ).list(); // s.close();
assertTrue(list.size() == 0); //
p.setAddress("L<EFBFBD>rkev<EFBFBD>nget 1"); // s = openSession();
s.update(p); //
list = s.createQuery( "select p from Person as p where p.address = 'L<>rkev<65>nget 1'" ).list(); // list = s.createQuery( "select p from Person as p where p.address = 'L<>rkev<65>nget 1'" ).list();
assertTrue(list.size() == 1); // assertTrue(list.size() == 0);
list = s.createQuery( "select p from Party as p where p.address = 'P. P. Street 8'" ).list(); // p.setAddress("L<EFBFBD>rkev<EFBFBD>nget 1");
assertTrue(list.size() == 0); // s.update(p);
// list = s.createQuery( "select p from Person as p where p.address = 'L<>rkev<65>nget 1'" ).list();
s.delete(p); // assertTrue(list.size() == 1);
list = s.createQuery( "select p from Person as p" ).list(); // list = s.createQuery( "select p from Party as p where p.address = 'P. P. Street 8'" ).list();
assertTrue(list.size() == 0); // assertTrue(list.size() == 0);
//
s.connection().commit(); // s.delete(p);
s.close(); // list = s.createQuery( "select p from Person as p" ).list();
} // assertTrue(list.size() == 0);
//
// s.connection().commit();
// s.close();
// }
} }