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