mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-15 15:44:55 +00:00
HHH-8612 correct FumTest's use of Date in a composite PK
This commit is contained in:
parent
3d932aeb33
commit
1b441f7720
@ -10,7 +10,7 @@
|
|||||||
<column name="string_" length="20"/>
|
<column name="string_" length="20"/>
|
||||||
</key-property>
|
</key-property>
|
||||||
<key-property name="short" column="short_"/>
|
<key-property name="short" column="short_"/>
|
||||||
<key-property name="date" column="date_" type="date"/>
|
<key-property name="date" column="date_" type="calendar"/>
|
||||||
</composite-id>
|
</composite-id>
|
||||||
<version name="version" type="long"/>
|
<version name="version" type="long"/>
|
||||||
<property name="serial" column="serial_"/>
|
<property name="serial" column="serial_"/>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<column name="string_" length="10"/>
|
<column name="string_" length="10"/>
|
||||||
</key-property>
|
</key-property>
|
||||||
<key-property name="short" column="short_"/>
|
<key-property name="short" column="short_"/>
|
||||||
<key-property name="date" column="date_" type="date"/>
|
<key-property name="date" column="date_" type="calendar"/>
|
||||||
</composite-id>
|
</composite-id>
|
||||||
<version name="vid" type="short" access="field"/>
|
<version name="vid" type="short" access="field"/>
|
||||||
<!--version name="lastUpdated" type="calendar"/-->
|
<!--version name="lastUpdated" type="calendar"/-->
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -32,7 +31,7 @@ public Fum(FumCompositeID id) throws SQLException, HibernateException {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
friends = new HashSet();
|
friends = new HashSet();
|
||||||
FumCompositeID fid = new FumCompositeID();
|
FumCompositeID fid = new FumCompositeID();
|
||||||
fid.setDate( new Date() );
|
fid.setDate( Calendar.getInstance() );
|
||||||
fid.setShort( (short) ( id.short_ + 33 ) );
|
fid.setShort( (short) ( id.short_ + 33 ) );
|
||||||
fid.setString( id.string_ + "dd" );
|
fid.setString( id.string_ + "dd" );
|
||||||
Fum f = new Fum();
|
Fum f = new Fum();
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
//$Id: FumCompositeID.java 4599 2004-09-26 05:18:27Z oneovthafew $
|
//$Id: FumCompositeID.java 4599 2004-09-26 05:18:27Z oneovthafew $
|
||||||
package org.hibernate.test.legacy;
|
package org.hibernate.test.legacy;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
|
||||||
public class FumCompositeID implements java.io.Serializable {
|
public class FumCompositeID implements java.io.Serializable {
|
||||||
String string_;
|
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_;
|
short short_;
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
FumCompositeID that = (FumCompositeID) other;
|
FumCompositeID that = (FumCompositeID) other;
|
||||||
@ -19,10 +23,10 @@ public String getString() {
|
|||||||
public void setString(String string_) {
|
public void setString(String string_) {
|
||||||
this.string_ = string_;
|
this.string_ = string_;
|
||||||
}
|
}
|
||||||
public java.util.Date getDate() {
|
public Calendar getDate() {
|
||||||
return date_;
|
return date_;
|
||||||
}
|
}
|
||||||
public void setDate(java.util.Date date_) {
|
public void setDate(Calendar date_) {
|
||||||
this.date_ = date_;
|
this.date_ = date_;
|
||||||
}
|
}
|
||||||
public short getShort() {
|
public short getShort() {
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
//$Id: FumTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
|
//$Id: FumTest.java 10977 2006-12-12 23:28:04Z steve.ebersole@jboss.com $
|
||||||
package org.hibernate.test.legacy;
|
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.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -9,6 +14,7 @@
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -19,8 +25,6 @@
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.FetchMode;
|
import org.hibernate.FetchMode;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
@ -40,16 +44,12 @@
|
|||||||
import org.hibernate.dialect.TimesTenDialect;
|
import org.hibernate.dialect.TimesTenDialect;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
import org.hibernate.testing.SkipForDialect;
|
||||||
import org.hibernate.transform.Transformers;
|
import org.hibernate.transform.Transformers;
|
||||||
import org.hibernate.type.DateType;
|
import org.hibernate.type.CalendarType;
|
||||||
import org.hibernate.type.EntityType;
|
import org.hibernate.type.EntityType;
|
||||||
import org.hibernate.type.StandardBasicTypes;
|
import org.hibernate.type.StandardBasicTypes;
|
||||||
import org.hibernate.type.StringType;
|
import org.hibernate.type.StringType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class FumTest extends LegacyTestCase {
|
public class FumTest extends LegacyTestCase {
|
||||||
private static short fumKeyShort = 1;
|
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.MONTH),
|
||||||
now.get(java.util.Calendar.DATE)
|
now.get(java.util.Calendar.DATE)
|
||||||
);
|
);
|
||||||
id.setDate( cal.getTime() );
|
id.setDate( cal );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
id.setDate( new Date() );
|
id.setDate( Calendar.getInstance() );
|
||||||
}
|
}
|
||||||
id.setString( str );
|
id.setString( str );
|
||||||
|
|
||||||
@ -338,19 +338,21 @@ private static FumCompositeID fumKey(String str, boolean aCompositeQueryTest) {
|
|||||||
public void testCompositeID() throws Exception {
|
public void testCompositeID() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction txn = s.beginTransaction();
|
Transaction txn = s.beginTransaction();
|
||||||
Fum fum = new Fum( fumKey("fum") );
|
FumCompositeID fumKey = fumKey("fum");
|
||||||
|
Fum fum = new Fum( fumKey );
|
||||||
fum.setFum("fee fi fo");
|
fum.setFum("fee fi fo");
|
||||||
s.save(fum);
|
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();
|
txn.commit();
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
txn = s.beginTransaction();
|
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 );
|
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");
|
fum2.setFum("fee fo fi");
|
||||||
fum.setFo(fum2);
|
fum.setFo(fum2);
|
||||||
s.save(fum2);
|
s.save(fum2);
|
||||||
@ -385,7 +387,8 @@ public void testCompositeID() throws Exception {
|
|||||||
public void testCompositeIDOneToOne() throws Exception {
|
public void testCompositeIDOneToOne() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction txn = s.beginTransaction();
|
Transaction txn = s.beginTransaction();
|
||||||
Fum fum = new Fum( fumKey("fum") );
|
FumCompositeID fumKey = fumKey("fum");
|
||||||
|
Fum fum = new Fum( fumKey );
|
||||||
fum.setFum("fee fi fo");
|
fum.setFum("fee fi fo");
|
||||||
//s.save(fum);
|
//s.save(fum);
|
||||||
Fumm fumm = new Fumm();
|
Fumm fumm = new Fumm();
|
||||||
@ -396,7 +399,7 @@ public void testCompositeIDOneToOne() throws Exception {
|
|||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
txn = s.beginTransaction();
|
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.getFum() );
|
||||||
s.delete(fumm);
|
s.delete(fumm);
|
||||||
txn.commit();
|
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
|
// 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'" )
|
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();
|
.list();
|
||||||
assertEquals( "find by composite key query with arguments", 4, vList.size() );
|
assertEquals( "find by composite key query with arguments", 4, vList.size() );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
@ -464,7 +467,7 @@ public void testCompositeIDQuery() throws Exception {
|
|||||||
assertTrue(types[0] instanceof StringType);
|
assertTrue(types[0] instanceof StringType);
|
||||||
assertTrue(types[1] instanceof EntityType);
|
assertTrue(types[1] instanceof EntityType);
|
||||||
assertTrue(types[2] instanceof StringType);
|
assertTrue(types[2] instanceof StringType);
|
||||||
assertTrue(types[3] instanceof DateType);
|
assertTrue(types[3] instanceof CalendarType);
|
||||||
Iterator iter = qu.iterate();
|
Iterator iter = qu.iterate();
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while ( iter.hasNext() ) {
|
while ( iter.hasNext() ) {
|
||||||
@ -589,7 +592,8 @@ public void testDeleteOwner() throws Exception {
|
|||||||
public void testCompositeIDs() throws Exception {
|
public void testCompositeIDs() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
s.beginTransaction();
|
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();
|
Properties props = new Properties();
|
||||||
props.setProperty("foo", "bar");
|
props.setProperty("foo", "bar");
|
||||||
props.setProperty("bar", "foo");
|
props.setProperty("bar", "foo");
|
||||||
@ -603,7 +607,7 @@ public void testCompositeIDs() throws Exception {
|
|||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
s.beginTransaction();
|
||||||
fo = (Fo) s.load( Fo.class, fumKey("an instance of fo") );
|
fo = (Fo) s.load( Fo.class, fumKey );
|
||||||
props = (Properties) fo.getSerial();
|
props = (Properties) fo.getSerial();
|
||||||
assertTrue( props.getProperty("foo").equals("bar") );
|
assertTrue( props.getProperty("foo").equals("bar") );
|
||||||
//assertTrue( props.contains("x") );
|
//assertTrue( props.contains("x") );
|
||||||
@ -615,7 +619,7 @@ public void testCompositeIDs() throws Exception {
|
|||||||
|
|
||||||
s = openSession();
|
s = openSession();
|
||||||
s.beginTransaction();
|
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( fo.getBuf()[1]==126 );
|
||||||
assertTrue(
|
assertTrue(
|
||||||
s.createQuery( "from Fo fo where fo.id.string like 'an instance of fo'" ).iterate().next()==fo
|
s.createQuery( "from Fo fo where fo.id.string like 'an instance of fo'" ).iterate().next()==fo
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<column name="string_" length="10"/>
|
<column name="string_" length="10"/>
|
||||||
</key-property>
|
</key-property>
|
||||||
<key-property name="short" column="short_"/>
|
<key-property name="short" column="short_"/>
|
||||||
<key-property name="date" column="date_" type="date"/>
|
<key-property name="date" column="date_" type="calendar"/>
|
||||||
</composite-id>
|
</composite-id>
|
||||||
<property name="locale"/>
|
<property name="locale"/>
|
||||||
<one-to-one name="fum" cascade="all" constrained="true"/>
|
<one-to-one name="fum" cascade="all" constrained="true"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user