Author: smarlow(a)redhat.com
Date: 2010-01-05 11:55:15 -0500 (Tue, 05 Jan 2010)
New Revision: 18414
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java
Log:
HHH-4683 Make sure @Enumerated works with @ElementCollection. Added Map test.
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2010-01-05
16:11:14 UTC (rev 18413)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java 2010-01-05
16:55:15 UTC (rev 18414)
@@ -20,6 +20,7 @@
import javax.persistence.OrderColumn;
import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.test.annotations.collectionelement.FavoriteFood;
/**
* @author Emmanuel Bernard
@@ -39,6 +40,7 @@
private int[] favoriteNumbers;
private Set<Toy> favoriteToys = new HashSet<Toy>();
private Set<Character> characters = new HashSet<Character>();
+ private Map<String, FavoriteFood> foods = new
HashMap<String,FavoriteFood>();
private Set<CountryAttitude> countryAttitudes = new
HashSet<CountryAttitude>();
@Id
@@ -122,6 +124,16 @@
this.characters = characters;
}
+ @ElementCollection
+ @Enumerated(EnumType.STRING)
+ public Map<String, FavoriteFood> getFavoriteFood() {
+ return foods;
+ }
+
+ public void setFavoriteFood(Map<String, FavoriteFood>foods) {
+ this.foods = foods;
+ }
+
@ElementCollection(fetch = FetchType.EAGER)
//@Where(clause = "b_likes=false")
public Set<CountryAttitude> getCountryAttitudes() {
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java 2010-01-05
16:11:14 UTC (rev 18413)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java 2010-01-05
16:55:15 UTC (rev 18414)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.test.annotations.collectionelement;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -40,6 +41,12 @@
boy.setFavoriteNumbers( favNbrs );
boy.getCharacters().add( Character.GENTLE );
boy.getCharacters().add( Character.CRAFTY );
+
+ HashMap<String,FavoriteFood> foods = new HashMap<String,FavoriteFood>();
+ foods.put( "breakfast", FavoriteFood.PIZZA);
+ foods.put( "lunch", FavoriteFood.KUNGPAOCHICKEN);
+ foods.put( "dinner", FavoriteFood.SUSHI);
+ boy.setFavoriteFood(foods);
s.persist( boy );
s.getTransaction().commit();
s.clear();
@@ -53,6 +60,9 @@
assertNotNull( boy.getFavoriteNumbers() );
assertEquals( 3, boy.getFavoriteNumbers()[1] );
assertTrue( boy.getCharacters().contains( Character.CRAFTY ) );
+ assertTrue( boy.getFavoriteFood().get("dinner").equals(FavoriteFood.SUSHI));
+ assertTrue(
boy.getFavoriteFood().get("lunch").equals(FavoriteFood.KUNGPAOCHICKEN));
+ assertTrue(
boy.getFavoriteFood().get("breakfast").equals(FavoriteFood.PIZZA));
List result = s.createQuery( "select boy from Boy boy join boy.nickNames names
where names = :name" )
.setParameter( "name", "Thing" ).list();
assertEquals( 1, result.size() );
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java
(rev 0)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java 2010-01-05
16:55:15 UTC (rev 18414)
@@ -0,0 +1,8 @@
+package org.hibernate.test.annotations.collectionelement;
+
+public enum FavoriteFood {
+ SUSHI,
+ KUNGPAOCHICKEN,
+ ROASTBEEF,
+ PIZZA
+}