From a3dd6de70f19de06630dada74178d7331d971e17 Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Tue, 5 Jan 2010 16:55:15 +0000 Subject: [PATCH] HHH-4683 Make sure @Enumerated works with @ElementCollection. Added Map test. git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18414 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../test/annotations/collectionelement/Boy.java | 12 ++++++++++++ .../collectionelement/CollectionElementTest.java | 10 ++++++++++ .../annotations/collectionelement/FavoriteFood.java | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java diff --git a/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java index c2902fbe78..ecc8229b47 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/Boy.java @@ -20,6 +20,7 @@ import javax.persistence.JoinColumn; import javax.persistence.OrderColumn; import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.test.annotations.collectionelement.FavoriteFood; /** * @author Emmanuel Bernard @@ -39,6 +40,7 @@ public class Boy { private int[] favoriteNumbers; private Set favoriteToys = new HashSet(); private Set characters = new HashSet(); + private Map foods = new HashMap(); private Set countryAttitudes = new HashSet(); @Id @@ -122,6 +124,16 @@ public class Boy { this.characters = characters; } + @ElementCollection + @Enumerated(EnumType.STRING) + public Map getFavoriteFood() { + return foods; + } + + public void setFavoriteFood(Mapfoods) { + this.foods = foods; + } + @ElementCollection(fetch = FetchType.EAGER) //@Where(clause = "b_likes=false") public Set getCountryAttitudes() { diff --git a/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java index d13790f687..3e58936646 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java @@ -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 @@ public class CollectionElementTest extends TestCase { boy.setFavoriteNumbers( favNbrs ); boy.getCharacters().add( Character.GENTLE ); boy.getCharacters().add( Character.CRAFTY ); + + HashMap foods = new HashMap(); + 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 @@ public class CollectionElementTest extends TestCase { 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() ); diff --git a/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java new file mode 100644 index 0000000000..70bbcd90a8 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/collectionelement/FavoriteFood.java @@ -0,0 +1,8 @@ +package org.hibernate.test.annotations.collectionelement; + +public enum FavoriteFood { + SUSHI, + KUNGPAOCHICKEN, + ROASTBEEF, + PIZZA +}