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
This commit is contained in:
parent
76202814a6
commit
a3dd6de70f
|
@ -20,6 +20,7 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.OrderColumn;
|
import javax.persistence.OrderColumn;
|
||||||
|
|
||||||
import org.hibernate.annotations.CollectionOfElements;
|
import org.hibernate.annotations.CollectionOfElements;
|
||||||
|
import org.hibernate.test.annotations.collectionelement.FavoriteFood;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -39,6 +40,7 @@ public class Boy {
|
||||||
private int[] favoriteNumbers;
|
private int[] favoriteNumbers;
|
||||||
private Set<Toy> favoriteToys = new HashSet<Toy>();
|
private Set<Toy> favoriteToys = new HashSet<Toy>();
|
||||||
private Set<Character> characters = new HashSet<Character>();
|
private Set<Character> characters = new HashSet<Character>();
|
||||||
|
private Map<String, FavoriteFood> foods = new HashMap<String,FavoriteFood>();
|
||||||
private Set<CountryAttitude> countryAttitudes = new HashSet<CountryAttitude>();
|
private Set<CountryAttitude> countryAttitudes = new HashSet<CountryAttitude>();
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@ -122,6 +124,16 @@ public class Boy {
|
||||||
this.characters = characters;
|
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)
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
//@Where(clause = "b_likes=false")
|
//@Where(clause = "b_likes=false")
|
||||||
public Set<CountryAttitude> getCountryAttitudes() {
|
public Set<CountryAttitude> getCountryAttitudes() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//$Id$
|
//$Id$
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
package org.hibernate.test.annotations.collectionelement;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -40,6 +41,12 @@ public class CollectionElementTest extends TestCase {
|
||||||
boy.setFavoriteNumbers( favNbrs );
|
boy.setFavoriteNumbers( favNbrs );
|
||||||
boy.getCharacters().add( Character.GENTLE );
|
boy.getCharacters().add( Character.GENTLE );
|
||||||
boy.getCharacters().add( Character.CRAFTY );
|
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.persist( boy );
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.clear();
|
s.clear();
|
||||||
|
@ -53,6 +60,9 @@ public class CollectionElementTest extends TestCase {
|
||||||
assertNotNull( boy.getFavoriteNumbers() );
|
assertNotNull( boy.getFavoriteNumbers() );
|
||||||
assertEquals( 3, boy.getFavoriteNumbers()[1] );
|
assertEquals( 3, boy.getFavoriteNumbers()[1] );
|
||||||
assertTrue( boy.getCharacters().contains( Character.CRAFTY ) );
|
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" )
|
List result = s.createQuery( "select boy from Boy boy join boy.nickNames names where names = :name" )
|
||||||
.setParameter( "name", "Thing" ).list();
|
.setParameter( "name", "Thing" ).list();
|
||||||
assertEquals( 1, result.size() );
|
assertEquals( 1, result.size() );
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package org.hibernate.test.annotations.collectionelement;
|
||||||
|
|
||||||
|
public enum FavoriteFood {
|
||||||
|
SUSHI,
|
||||||
|
KUNGPAOCHICKEN,
|
||||||
|
ROASTBEEF,
|
||||||
|
PIZZA
|
||||||
|
}
|
Loading…
Reference in New Issue