@Test
public void updateOnDirtyObjectWhenQuery() throws Exception {
// now test it can happen at load of another object
// 1st
Container container = new Container();
String title = "Test container #"+UUIDGenerator.generateUuid();
container.setTitle(title);
container.setPreLoop("pre"); container.setPostLoop("post");
List<ContainerStructure> containerStructureList = new ArrayList<ContainerStructure>();
ContainerStructure cs=new ContainerStructure();
cs.setStructureId(StructureCache.getStructureByVelocityVarName("webPageContent").getInode());
cs.setCode("$body");
containerStructureList.add(cs);
container = APILocator.getContainerAPI().save(container, containerStructureList, host, user, false);
String cInode=container.getInode();
// 2nd
container = new Container();
String title2 = "Test 2nd container #"+UUIDGenerator.generateUuid();
container.setTitle(title2);
container.setPreLoop("pre"); container.setPostLoop("post");
containerStructureList = new ArrayList<ContainerStructure>();
cs=new ContainerStructure();
cs.setStructureId(StructureCache.getStructureByVelocityVarName("webPageContent").getInode());
cs.setCode("$body"); containerStructureList.add(cs);
container = APILocator.getContainerAPI().save(container, containerStructureList, host, user, false);
String cInode2=container.getInode();
container = null;
HibernateUtil.closeSession();
// load the first and make it dirty
Container fst = (Container)HibernateUtil.load(Container.class, cInode);
fst.setTitle("my dirty title 2");
// load the second. it might trigger an update on the first one
HibernateUtil hh = new HibernateUtil(Container.class);
hh.setQuery("from "+Container.class.getName()+" c where c.inode=?");
hh.setParam(cInode2);
Container cc = (Container)hh.load();
Assert.assertEquals(title2, cc.getTitle());
// lets see if in the db it remains the same
DotConnect dc = new DotConnect();
dc.setSQL("select title from containers where inode=?");
dc.addParam(cInode);