From: <one...@us...> - 2002-11-07 10:11:03
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/test In directory usw-pr-cvs1:/tmp/cvs-serv24773/hibernate/test Modified Files: FooBarTest.java MasterDetailTest.java Stuff.hbm.xml Stuff.java Log Message: fixed a bug with embedded composite-ids and outerjoin fetching Index: FooBarTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/FooBarTest.java,v retrieving revision 1.217 retrieving revision 1.218 diff -C2 -d -r1.217 -r1.218 *** FooBarTest.java 5 Nov 2002 16:58:14 -0000 1.217 --- FooBarTest.java 7 Nov 2002 10:10:59 -0000 1.218 *************** *** 50,53 **** --- 50,106 ---- } + public void testAssociationId() throws Exception { + Session s = sessions.openSession(); + Transaction t = s.beginTransaction(); + Bar bar = new Bar(); + String id = (String) s.save(bar); + MoreStuff more = new MoreStuff(); + more.setName("More Stuff"); + more.setIntId(12); + more.setStringId("id"); + Stuff stuf = new Stuff(); + stuf.setMoreStuff(more); + more.setStuffs( new ArrayList() ); + more.getStuffs().add(stuf); + stuf.setFoo(bar); + stuf.setId(1234); + stuf.setProperty( TimeZone.getDefault() ); + s.save(more); + t.commit(); + s.close(); + + s = sessions.openSession(); + t = s.beginTransaction(); + assertTrue( s.find( + "from s in class Stuff where s.foo.id = ? and s.id.id = ? and s.moreStuff.id.intId = ? and s.moreStuff.id.stringId = ?", + new Object[] { bar, new Long(1234), new Integer(12), "id" }, + new Type[] { Hibernate.association(Foo.class), Hibernate.LONG, Hibernate.INTEGER, Hibernate.STRING } + ).size()==1 ); + assertTrue( s.find( + "from s in class Stuff where s.foo.id = ? and s.id.id = ? and s.moreStuff.name = ?", + new Object[] { bar, new Long(1234), "More Stuff" }, + new Type[] { Hibernate.association(Foo.class), Hibernate.LONG, Hibernate.STRING } + ).size()==1 ); + s.find("from s in class Stuff where s.foo.string is not null"); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + FooProxy foo = (FooProxy) s.load(Foo.class, id); + s.load(more, more); + Stuff stuff = new Stuff(); + stuff.setFoo(foo); + stuff.setId(1234); + stuff.setMoreStuff(more); + s.load(stuff, stuff); + assertTrue( stuff.getProperty().equals( TimeZone.getDefault() ) ); + assertTrue( stuff.getMoreStuff().getName().equals("More Stuff") ); + s.delete( stuff.getMoreStuff() ); + s.delete(foo); + t.commit(); + s.close(); + } + + public void testCompositeKeyPathExpressions() throws Exception { Session s = sessions.openSession(); *************** *** 2625,2664 **** } - public void testAssociationId() throws Exception { - Session s = sessions.openSession(); - Transaction t = s.beginTransaction(); - Bar bar = new Bar(); - String id = (String) s.save(bar); - Stuff stuf = new Stuff(); - stuf.setFoo(bar); - stuf.setId(1234); - stuf.setProperty( TimeZone.getDefault() ); - s.save(stuf); - t.commit(); - s.close(); - s = sessions.openSession(); - t = s.beginTransaction(); - assertTrue( - s.find("from s in class Stuff where s.foo.id = ? and s.id.id = ?", - new Object[] { bar, new Long(1234) }, new Type[] { Hibernate.association(Foo.class), Hibernate.LONG } ) - .size()==1 ); - s.find("from s in class Stuff where s.foo.string is not null"); - t.commit(); - s.close(); - s = sessions.openSession(); - t = s.beginTransaction(); - FooProxy foo = (FooProxy) s.load(Foo.class, id); - Stuff stuff = new Stuff(); - stuff.setFoo(foo); - stuff.setId(1234); - s.load(stuff, stuff); - assertTrue( stuff.getProperty().equals( TimeZone.getDefault() ) ); - s.delete(stuff); - s.delete(foo); - t.commit(); - s.close(); - } - - public static Test suite() throws Exception { try { --- 2678,2681 ---- Index: MasterDetailTest.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/MasterDetailTest.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** MasterDetailTest.java 5 Nov 2002 16:58:14 -0000 1.38 --- MasterDetailTest.java 7 Nov 2002 10:10:59 -0000 1.39 *************** *** 26,29 **** --- 26,55 ---- } + public void testNonLazyBidirectional() throws Exception { + Session s = sessions.openSession(); + Transaction t = s.beginTransaction(); + Single sin = new Single(); + sin.setId("asdfds"); + sin.setString("adsa asdfasd"); + Several sev = new Several(); + sev.setId("asdfasdfasd"); + sev.setString("asd ddd"); + sin.getSeveral().add(sev); + sev.setSingle(sin); + s.save(sin); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + sin = (Single) s.load( Single.class, sin ); + t.commit(); + s.close(); + s = sessions.openSession(); + t = s.beginTransaction(); + sev = (Several) s.load( Several.class, sev ); + t.commit(); + s.close(); + } + public void testCollectionQuery() throws Exception { Session s = sessions.openSession(); *************** *** 431,439 **** s.close(); } ! public static Test suite() throws Exception { TestCase.exportSchema( ! new String[] { "MasterDetail.hbm.xml", "Custom.hbm.xml", "Category.hbm.xml", "Nameable.hbm.xml" } ); return new TestSuite(MasterDetailTest.class); --- 457,465 ---- s.close(); } ! public static Test suite() throws Exception { TestCase.exportSchema( ! new String[] { "MasterDetail.hbm.xml", "Custom.hbm.xml", "Category.hbm.xml", "Nameable.hbm.xml", "SingleSeveral.hbm.xml" } ); return new TestSuite(MasterDetailTest.class); Index: Stuff.hbm.xml =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/Stuff.hbm.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Stuff.hbm.xml 7 Oct 2002 18:08:46 -0000 1.3 --- Stuff.hbm.xml 7 Nov 2002 10:10:59 -0000 1.4 *************** *** 2,6 **** <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd" > <hibernate-mapping> ! <class name="cirrus.hibernate.test.Stuff"> <composite-id> --- 2,22 ---- <!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd" > <hibernate-mapping> ! ! <class name="cirrus.hibernate.test.MoreStuff"> ! <composite-id> ! <key-property name="intId"/> ! <key-property name="stringId"/> ! </composite-id> ! <property name="name"/> ! <bag role="stuffs" readonly="true" lazy="false" cascade="all"> ! <key> ! <!--unfortunately have to specify not-null here because of limitation in schema export....--> ! <column name="moreInt" not-null="true"/> ! <column name="moreString" not-null="true"/> ! </key> ! <one-to-many class="cirrus.hibernate.test.Stuff"/> ! </bag> ! </class> ! <class name="cirrus.hibernate.test.Stuff"> <composite-id> *************** *** 8,11 **** --- 24,31 ---- <key-many-to-one name="foo" class="cirrus.hibernate.test.Foo"/> </composite-id> + <many-to-one name="moreStuff" class="cirrus.hibernate.test.MoreStuff"> + <column name="moreInt"/> + <column name="moreString"/> + </many-to-one> <property name="property"/> </class> Index: Stuff.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/test/Stuff.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Stuff.java 5 Oct 2002 18:07:50 -0000 1.1 --- Stuff.java 7 Nov 2002 10:10:59 -0000 1.2 *************** *** 14,22 **** if ( ! (other instanceof Stuff) ) return false; Stuff otherStuff = (Stuff) other; ! return otherStuff.id==id && otherStuff.foo==foo; } private long id; private FooProxy foo; private TimeZone property; /** --- 14,23 ---- if ( ! (other instanceof Stuff) ) return false; Stuff otherStuff = (Stuff) other; ! return otherStuff.id==id && otherStuff.foo==foo && otherStuff.moreStuff==moreStuff; } private long id; private FooProxy foo; + private MoreStuff moreStuff; private TimeZone property; /** *************** *** 66,69 **** --- 67,86 ---- public void setProperty(TimeZone property) { this.property = property; + } + + /** + * Returns the moreStuff. + * @return MoreStuff + */ + public MoreStuff getMoreStuff() { + return moreStuff; + } + + /** + * Sets the moreStuff. + * @param moreStuff The moreStuff to set + */ + public void setMoreStuff(MoreStuff moreStuff) { + this.moreStuff = moreStuff; } |