From: <one...@us...> - 2003-04-16 01:13:32
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test In directory sc8-pr-cvs1:/tmp/cvs-serv23316/hibernate/test Modified Files: MultiTableTest.java Log Message: fixed a bug where references to self from an entity with a natively generated id were not getting nullified Index: MultiTableTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/test/MultiTableTest.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** MultiTableTest.java 6 Apr 2003 10:11:11 -0000 1.13 --- MultiTableTest.java 16 Apr 2003 01:13:28 -0000 1.14 *************** *** 364,368 **** public void testMultiTableCollections() throws Exception { ! if ( dialect instanceof SybaseDialect ) return; Session s = sessions.openSession(); --- 364,368 ---- public void testMultiTableCollections() throws Exception { ! //if ( dialect instanceof SybaseDialect ) return; Session s = sessions.openSession(); *************** *** 377,382 **** simp.setName("simp"); //simp.setCount(132); ! s.save( multi, new Long(123) ); ! s.save( simp, new Long(1234) ); LessSimple ls = new LessSimple(); ls.setOther(ls); --- 377,392 ---- simp.setName("simp"); //simp.setCount(132); ! Serializable mid; ! Serializable sid; ! if ( dialect instanceof SybaseDialect ) { ! mid = s.save(multi); ! sid = s.save(simp); ! } ! else { ! mid = new Long(123); ! sid = new Long(1234); ! s.save(multi, mid); ! s.save(simp, sid); ! } LessSimple ls = new LessSimple(); ls.setOther(ls); *************** *** 388,398 **** set.add(multi); set.add(simp); ! s.save( ls, new Long(2) ); t.commit(); s.close(); ! s = sessions.openSession(); t = s.beginTransaction(); ! ls = (LessSimple) s.load( LessSimple.class, new Long(2) ); assertTrue( ls.getOther()==ls && ls.getAnother()==ls && ls.getYetanother()==ls ); assertTrue( ls.getSet().size()==2 ); --- 398,416 ---- set.add(multi); set.add(simp); ! Serializable id; ! if ( dialect instanceof SybaseDialect ) { ! id = s.save(ls); ! } ! else { ! id = new Long(2); ! s.save( ls, new Long(2) ); ! } t.commit(); s.close(); ! assertTrue( ls.getOther()==ls && ls.getAnother()==ls && ls.getYetanother()==ls ); ! s = sessions.openSession(); t = s.beginTransaction(); ! ls = (LessSimple) s.load(LessSimple.class, id); assertTrue( ls.getOther()==ls && ls.getAnother()==ls && ls.getYetanother()==ls ); assertTrue( ls.getSet().size()==2 ); *************** *** 407,410 **** --- 425,477 ---- assertTrue( foundSimple==2 && foundMulti==1 ); assertTrue( s.delete("from s in class Simple")==3 ); + t.commit(); + s.close(); + } + + public void testMultiTableManyToOne() throws Exception { + + Session s = sessions.openSession(); + Transaction t = s.beginTransaction(); + assertTrue( s.find("from s in class Simple").size()==0 ); + Multi multi = new Multi(); + multi.setExtraProp("extra"); + //multi.setCount(666); + multi.setName("name"); + Simple simp = new Simple(); + simp.setDate( new Date() ); + simp.setName("simp"); + //simp.setCount(132); + Serializable mid; + if ( dialect instanceof SybaseDialect ) { + mid = s.save(multi); + } + else { + mid = new Long(123); + s.save(multi, mid); + } + LessSimple ls = new LessSimple(); + ls.setOther(ls); + ls.setAnother(multi); + ls.setYetanother(ls); + ls.setName("Less Simple"); + Serializable id; + if ( dialect instanceof SybaseDialect ) { + id = s.save(ls); + } + else { + id = new Long(2); + s.save( ls, new Long(2) ); + } + t.commit(); + s.close(); + assertTrue( ls.getOther()==ls && ls.getAnother()==multi && ls.getYetanother()==ls ); + + s = sessions.openSession(); + t = s.beginTransaction(); + ls = (LessSimple) s.load(LessSimple.class, id); + assertTrue( ls.getOther()==ls && ls.getYetanother()==ls ); + assertTrue( ls.getAnother().getName().equals("name") && ls.getAnother() instanceof Multi ); + s.delete(ls); + s.delete( ls.getAnother() ); t.commit(); s.close(); |