Author: epbernard
Date: 2006-11-29 10:23:36 -0500 (Wed, 29 Nov 2006)
New Revision: 10881
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Software.java
Log:
ANN-491 more tests
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-11-29
15:18:34 UTC (rev 10880)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2006-11-29
15:23:36 UTC (rev 10881)
@@ -424,8 +424,8 @@
trainee2.setName( "Emmanuel" );
s.persist( trainee );
s.persist( trainee2 );
- training.getTrainees().put("Jim", trainee);
- training.getTrainees().put("Emmanuel", trainee2);
+ training.getTrainees().put( "Jim", trainee );
+ training.getTrainees().put( "Emmanuel", trainee2 );
s.persist( training );
s.flush();
s.clear();
@@ -436,6 +436,44 @@
s.close();
}
+ public void testMapKeyLoad() throws Exception {
+ Session s;
+ Transaction tx;
+ s = openSession();
+ tx = s.beginTransaction();
+ Software hibernate = new Software();
+ hibernate.setName( "Hibernate" );
+ Version v1 = new Version();
+ v1.setCodeName( "HumbaHumba" );
+ v1.setNumber( "1.0" );
+ v1.setSoftware( hibernate );
+ hibernate.addVersion( v1 );
+ s.persist( hibernate );
+ s.persist( v1 );
+ tx.commit();
+ s.clear();
+ tx = s.beginTransaction();
+ hibernate = (Software) s.get( Software.class, "Hibernate" );
+ assertEquals(1, hibernate.getVersions().size() );
+ Version v2 = new Version();
+ v2.setCodeName( "HumbaHumba2" );
+ v2.setNumber( "2.0" );
+ v2.setSoftware( hibernate );
+ hibernate.addVersion( v2 );
+ assertEquals( "One loaded persisted version, and one just added", 2,
hibernate.getVersions().size() );
+ tx.commit();
+ s.clear();
+ tx = s.beginTransaction();
+ hibernate = (Software) s.get( Software.class, "Hibernate" );
+ for ( Version v : hibernate.getVersions().values() ) {
+ s.delete( v );
+ }
+ s.delete( hibernate );
+ tx.commit();
+ s.close();
+ }
+
+
public IndexedCollectionTest(String x) {
super( x );
}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Software.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Software.java 2006-11-29
15:18:34 UTC (rev 10880)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/indexcoll/Software.java 2006-11-29
15:23:36 UTC (rev 10881)
@@ -2,6 +2,7 @@
package org.hibernate.test.annotations.indexcoll;
import java.util.Map;
+import java.util.HashMap;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.MapKey;
@@ -13,7 +14,7 @@
@Entity
public class Software {
private String name;
- private Map<String, Version> versions;
+ private Map<String, Version> versions = new HashMap<String, Version>();
@Id
public String getName() {
@@ -33,4 +34,8 @@
public void setVersions(Map<String, Version> versions) {
this.versions = versions;
}
+
+ public void addVersion(Version version) {
+ this.versions.put(version.getCodeName(), version);
+ }
}
Show replies by date