diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fo.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fo.hbm.xml index 00b3d34de0..2e84d088d9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fo.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fo.hbm.xml @@ -10,7 +10,7 @@ - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.hbm.xml index 6b5b998c8f..bc9a35abf5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.hbm.xml @@ -12,7 +12,7 @@ - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.java index aa475d94a2..3e07394122 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fum.java @@ -3,7 +3,6 @@ import java.io.Serializable; import java.sql.SQLException; import java.util.Calendar; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -32,7 +31,7 @@ public Fum(FumCompositeID id) throws SQLException, HibernateException { this.id = id; friends = new HashSet(); FumCompositeID fid = new FumCompositeID(); - fid.setDate( new Date() ); + fid.setDate( Calendar.getInstance() ); fid.setShort( (short) ( id.short_ + 33 ) ); fid.setString( id.string_ + "dd" ); Fum f = new Fum(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/FumCompositeID.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/FumCompositeID.java index d414cf2afc..b1f36a3f18 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/FumCompositeID.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/FumCompositeID.java @@ -1,10 +1,14 @@ //$Id: FumCompositeID.java 4599 2004-09-26 05:18:27Z oneovthafew $ package org.hibernate.test.legacy; +import java.util.Calendar; + public class FumCompositeID implements java.io.Serializable { String string_; - java.util.Date date_; + // this CANNOT be a Date -- they are forcefully stripped of time, changing the PK + // TODO: having a date/calendar as a PK is horrible... + Calendar date_; short short_; public boolean equals(Object other) { FumCompositeID that = (FumCompositeID) other; @@ -19,10 +23,10 @@ public String getString() { public void setString(String string_) { this.string_ = string_; } - public java.util.Date getDate() { + public Calendar getDate() { return date_; } - public void setDate(java.util.Date date_) { + public void setDate(Calendar date_) { this.date_ = date_; } public short getShort() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/FumTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/FumTest.java index 9c07f9a226..6fb70a2e51 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/FumTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/FumTest.java @@ -1,6 +1,11 @@ //$Id: FumTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $ package org.hibernate.test.legacy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -9,6 +14,7 @@ import java.io.Serializable; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashSet; @@ -19,8 +25,6 @@ import java.util.Properties; import java.util.Set; -import org.junit.Test; - import org.hibernate.Criteria; import org.hibernate.FetchMode; import org.hibernate.FlushMode; @@ -40,16 +44,12 @@ import org.hibernate.dialect.TimesTenDialect; import org.hibernate.testing.SkipForDialect; import org.hibernate.transform.Transformers; -import org.hibernate.type.DateType; +import org.hibernate.type.CalendarType; import org.hibernate.type.EntityType; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StringType; import org.hibernate.type.Type; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; public class FumTest extends LegacyTestCase { private static short fumKeyShort = 1; @@ -317,10 +317,10 @@ private static FumCompositeID fumKey(String str, boolean aCompositeQueryTest) { now.get(java.util.Calendar.MONTH), now.get(java.util.Calendar.DATE) ); - id.setDate( cal.getTime() ); + id.setDate( cal ); } else { - id.setDate( new Date() ); + id.setDate( Calendar.getInstance() ); } id.setString( str ); @@ -338,19 +338,21 @@ private static FumCompositeID fumKey(String str, boolean aCompositeQueryTest) { public void testCompositeID() throws Exception { Session s = openSession(); Transaction txn = s.beginTransaction(); - Fum fum = new Fum( fumKey("fum") ); + FumCompositeID fumKey = fumKey("fum"); + Fum fum = new Fum( fumKey ); fum.setFum("fee fi fo"); s.save(fum); - assertTrue( "load by composite key", fum==s.load( Fum.class, fumKey("fum") ) ); + assertTrue( "load by composite key", fum==s.load( Fum.class, fumKey ) ); txn.commit(); s.close(); s = openSession(); txn = s.beginTransaction(); - fum = (Fum) s.load( Fum.class, fumKey("fum"), LockMode.UPGRADE ); + fum = (Fum) s.load( Fum.class, fumKey, LockMode.UPGRADE ); assertTrue( "load by composite key", fum!=null ); - Fum fum2 = new Fum( fumKey("fi") ); + FumCompositeID fumKey2 = fumKey("fi"); + Fum fum2 = new Fum( fumKey2 ); fum2.setFum("fee fo fi"); fum.setFo(fum2); s.save(fum2); @@ -385,7 +387,8 @@ public void testCompositeID() throws Exception { public void testCompositeIDOneToOne() throws Exception { Session s = openSession(); Transaction txn = s.beginTransaction(); - Fum fum = new Fum( fumKey("fum") ); + FumCompositeID fumKey = fumKey("fum"); + Fum fum = new Fum( fumKey ); fum.setFum("fee fi fo"); //s.save(fum); Fumm fumm = new Fumm(); @@ -396,7 +399,7 @@ public void testCompositeIDOneToOne() throws Exception { s = openSession(); txn = s.beginTransaction(); - fumm = (Fumm) s.load( Fumm.class, fumKey("fum") ); + fumm = (Fumm) s.load( Fumm.class, fumKey ); //s.delete( fumm.getFum() ); s.delete(fumm); txn.commit(); @@ -441,7 +444,7 @@ public void testCompositeIDQuery() throws Exception { // Make sure we can return all of the objects by searching by the date id vList = s.createQuery( "from Fum fum where fum.id.date <= ? and not fum.fum='FRIEND'" ) - .setParameter( 0, new Date(), StandardBasicTypes.DATE ) + .setParameter( 0, Calendar.getInstance(), StandardBasicTypes.CALENDAR ) .list(); assertEquals( "find by composite key query with arguments", 4, vList.size() ); s.getTransaction().commit(); @@ -464,7 +467,7 @@ public void testCompositeIDQuery() throws Exception { assertTrue(types[0] instanceof StringType); assertTrue(types[1] instanceof EntityType); assertTrue(types[2] instanceof StringType); - assertTrue(types[3] instanceof DateType); + assertTrue(types[3] instanceof CalendarType); Iterator iter = qu.iterate(); int j = 0; while ( iter.hasNext() ) { @@ -589,7 +592,8 @@ public void testDeleteOwner() throws Exception { public void testCompositeIDs() throws Exception { Session s = openSession(); s.beginTransaction(); - Fo fo = Fo.newFo( fumKey("an instance of fo") ); + FumCompositeID fumKey = fumKey("an instance of fo"); + Fo fo = Fo.newFo( fumKey ); Properties props = new Properties(); props.setProperty("foo", "bar"); props.setProperty("bar", "foo"); @@ -603,7 +607,7 @@ public void testCompositeIDs() throws Exception { s = openSession(); s.beginTransaction(); - fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") ); + fo = (Fo) s.load( Fo.class, fumKey ); props = (Properties) fo.getSerial(); assertTrue( props.getProperty("foo").equals("bar") ); //assertTrue( props.contains("x") ); @@ -615,7 +619,7 @@ public void testCompositeIDs() throws Exception { s = openSession(); s.beginTransaction(); - fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") ); + fo = (Fo) s.load( Fo.class, fumKey ); assertTrue( fo.getBuf()[1]==126 ); assertTrue( s.createQuery( "from Fo fo where fo.id.string like 'an instance of fo'" ).iterate().next()==fo diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fumm.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fumm.hbm.xml index e7e8e60ece..7115bce1e1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/Fumm.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/Fumm.hbm.xml @@ -10,7 +10,7 @@ - +