HHH-7702 Add support for collections of (aggregated) composite elements

This commit is contained in:
Brett Meyer 2012-11-19 19:22:33 -05:00
parent 1c992b1faf
commit 037f081793
6 changed files with 334 additions and 335 deletions

View File

@ -52,6 +52,8 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
private List<AttributeSource> attributeSources private List<AttributeSource> attributeSources
= new ArrayList<AttributeSource>(); = new ArrayList<AttributeSource>();
private String parentReferenceAttributeName;
public CompositePluralAttributeElementSourceImpl( public CompositePluralAttributeElementSourceImpl(
AssociationAttribute associationAttribute, AssociationAttribute associationAttribute,
RootEntityClass rootEntityClass ) { RootEntityClass rootEntityClass ) {
@ -111,8 +113,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
@Override @Override
public String getParentReferenceAttributeName() { public String getParentReferenceAttributeName() {
// TODO: Is this correct? return parentReferenceAttributeName;
return associationAttribute.getName();
} }
@Override @Override
@ -125,6 +126,9 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
EmbeddableClass embeddableClass = rootEntityClass EmbeddableClass embeddableClass = rootEntityClass
.getCollectionEmbeddedClasses() .getCollectionEmbeddedClasses()
.get( associationAttribute.getName() ); .get( associationAttribute.getName() );
parentReferenceAttributeName = embeddableClass.getParentReferencingAttributeName();
// TODO: Duplicates code in ComponentAttributeSourceImpl. // TODO: Duplicates code in ComponentAttributeSourceImpl.
for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) { for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) {
AttributeOverride attributeOverride = null; AttributeOverride attributeOverride = null;

View File

@ -23,25 +23,23 @@
*/ */
package org.hibernate.test.annotations.beanvalidation; package org.hibernate.test.annotations.beanvalidation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.math.BigDecimal; import java.math.BigDecimal;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import org.junit.Test;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@FailureExpectedWithNewMetamodel
public class HibernateTraversableResolverTest extends BaseCoreFunctionalTestCase { public class HibernateTraversableResolverTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNonLazyAssocFieldWithConstraintsFailureExpected() { public void testNonLazyAssocFieldWithConstraintsFailureExpected() {

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides; import javax.persistence.AttributeOverrides;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
@ -34,16 +35,16 @@ public class Boy {
private Integer id; private Integer id;
private String firstName; private String firstName;
private String lastName; private String lastName;
// private Set<String> nickNames = new HashSet<String>(); private Set<String> nickNames = new HashSet<String>();
// private Set<String> hatedNames = new HashSet<String>(); private Set<String> hatedNames = new HashSet<String>();
// private Set<String> preferredNames = new HashSet<String>(); private Set<String> preferredNames = new HashSet<String>();
// private Map<String, Integer> scorePerNickName = new HashMap<String, Integer>(); private Map<String, Integer> scorePerNickName = new HashMap<String, Integer>();
// private Map<String, Integer> scorePerPreferredName = new HashMap<String, Integer>(); private Map<String, Integer> scorePerPreferredName = new HashMap<String, Integer>();
// 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 Map<String, FavoriteFood> foods = new HashMap<String,FavoriteFood>();
// private Set<CountryAttitude> countryAttitudes = new HashSet<CountryAttitude>(); private Set<CountryAttitude> countryAttitudes = new HashSet<CountryAttitude>();
@Id @Id
@GeneratedValue @GeneratedValue
@ -71,70 +72,70 @@ public class Boy {
this.lastName = lastName; this.lastName = lastName;
} }
// @ElementCollection @ElementCollection
// public Set<String> getNickNames() { public Set<String> getNickNames() {
// return nickNames; return nickNames;
// } }
//
// public void setNickNames(Set<String> nickName) { public void setNickNames(Set<String> nickName) {
// this.nickNames = nickName; this.nickNames = nickName;
// } }
//
// @ElementCollection //default column names @ElementCollection //default column names
// public Set<String> getHatedNames() { public Set<String> getHatedNames() {
// return hatedNames; return hatedNames;
// } }
//
// public void setHatedNames(Set<String> hatedNames) { public void setHatedNames(Set<String> hatedNames) {
// this.hatedNames = hatedNames; this.hatedNames = hatedNames;
// } }
//
// @ElementCollection //default column names @ElementCollection //default column names
// @Column @Column
// public Set<String> getPreferredNames() { public Set<String> getPreferredNames() {
// return preferredNames; return preferredNames;
// } }
//
// public void setPreferredNames(Set<String> preferredNames) { public void setPreferredNames(Set<String> preferredNames) {
// this.preferredNames = preferredNames; this.preferredNames = preferredNames;
// } }
//
// @ElementCollection @ElementCollection
// @MapKeyColumn(nullable=false) @MapKeyColumn(nullable=false)
// public Map<String, Integer> getScorePerPreferredName() { public Map<String, Integer> getScorePerPreferredName() {
// return scorePerPreferredName; return scorePerPreferredName;
// } }
//
// public void setScorePerPreferredName(Map<String, Integer> scorePerPreferredName) { public void setScorePerPreferredName(Map<String, Integer> scorePerPreferredName) {
// this.scorePerPreferredName = scorePerPreferredName; this.scorePerPreferredName = scorePerPreferredName;
// } }
//
// @ElementCollection @ElementCollection
// @CollectionTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name = "BoyId")) @CollectionTable(name = "ScorePerNickName", joinColumns = @JoinColumn(name = "BoyId"))
// @Column(name = "score", nullable = false) @Column(name = "score", nullable = false)
// @MapKeyColumn(nullable=false) @MapKeyColumn(nullable=false)
// public Map<String, Integer> getScorePerNickName() { public Map<String, Integer> getScorePerNickName() {
// return scorePerNickName; return scorePerNickName;
// } }
//
// public void setScorePerNickName(Map<String, Integer> scorePerNickName) { public void setScorePerNickName(Map<String, Integer> scorePerNickName) {
// this.scorePerNickName = scorePerNickName; this.scorePerNickName = scorePerNickName;
// } }
//
// @ElementCollection @ElementCollection
// @CollectionTable( @CollectionTable(
// name = "BoyFavoriteNumbers", name = "BoyFavoriteNumbers",
// joinColumns = @JoinColumn(name = "BoyId") joinColumns = @JoinColumn(name = "BoyId")
// ) )
// @Column(name = "favoriteNumber", nullable = false) @Column(name = "favoriteNumber", nullable = false)
// @OrderColumn(name = "nbr_index") @OrderColumn(name = "nbr_index")
// public int[] getFavoriteNumbers() { public int[] getFavoriteNumbers() {
// return favoriteNumbers; return favoriteNumbers;
// } }
//
// public void setFavoriteNumbers(int[] favoriteNumbers) { public void setFavoriteNumbers(int[] favoriteNumbers) {
// this.favoriteNumbers = favoriteNumbers; this.favoriteNumbers = favoriteNumbers;
// } }
@ElementCollection @ElementCollection
@AttributeOverride(name = "element.serial", column = @Column(name = "serial_nbr")) @AttributeOverride(name = "element.serial", column = @Column(name = "serial_nbr"))
public Set<Toy> getFavoriteToys() { public Set<Toy> getFavoriteToys() {
@ -145,36 +146,36 @@ public class Boy {
this.favoriteToys = favoriteToys; this.favoriteToys = favoriteToys;
} }
// @ElementCollection @ElementCollection
// @Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
// @Column(name = "`characters`") @Column(name = "`characters`")
// public Set<Character> getCharacters() { public Set<Character> getCharacters() {
// return characters; return characters;
// } }
//
// public void setCharacters(Set<Character> characters) { public void setCharacters(Set<Character> characters) {
// this.characters = characters; this.characters = characters;
// } }
//
// @ElementCollection @ElementCollection
// @Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
// @MapKeyColumn(nullable=false) @MapKeyColumn(nullable=false)
// public Map<String, FavoriteFood> getFavoriteFood() { public Map<String, FavoriteFood> getFavoriteFood() {
// return foods; return foods;
// } }
//
// public void setFavoriteFood(Map<String, FavoriteFood>foods) { public void setFavoriteFood(Map<String, FavoriteFood>foods) {
// this.foods = 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() {
// return countryAttitudes; return countryAttitudes;
// } }
//
// public void setCountryAttitudes(Set<CountryAttitude> countryAttitudes) { public void setCountryAttitudes(Set<CountryAttitude> countryAttitudes) {
// this.countryAttitudes = countryAttitudes; this.countryAttitudes = countryAttitudes;
// } }
} }

View File

@ -23,13 +23,15 @@
*/ */
package org.hibernate.test.annotations.collectionelement; package org.hibernate.test.annotations.collectionelement;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.junit.Test;
import org.hibernate.Filter; import org.hibernate.Filter;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session; import org.hibernate.Session;
@ -38,70 +40,67 @@ import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
import org.hibernate.test.annotations.Country; import org.hibernate.test.annotations.Country;
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
//@FailureExpectedWithNewMetamodel @FailureExpectedWithNewMetamodel
public class CollectionElementTest extends BaseCoreFunctionalTestCase { public class CollectionElementTest extends BaseCoreFunctionalTestCase {
// @Test @Test
// public void testSimpleElement() throws Exception { public void testSimpleElement() throws Exception {
// assertEquals( assertEquals(
// "BoyFavoriteNumbers", "BoyFavoriteNumbers",
// configuration().getCollectionMapping( Boy.class.getName() + '.' + "favoriteNumbers" ) configuration().getCollectionMapping( Boy.class.getName() + '.' + "favoriteNumbers" )
// .getCollectionTable().getName() .getCollectionTable().getName()
// ); );
// Session s = openSession(); Session s = openSession();
// s.getTransaction().begin(); s.getTransaction().begin();
// Boy boy = new Boy(); Boy boy = new Boy();
// boy.setFirstName( "John" ); boy.setFirstName( "John" );
// boy.setLastName( "Doe" ); boy.setLastName( "Doe" );
// boy.getNickNames().add( "Johnny" ); boy.getNickNames().add( "Johnny" );
// boy.getNickNames().add( "Thing" ); boy.getNickNames().add( "Thing" );
// boy.getScorePerNickName().put( "Johnny", new Integer( 3 ) ); boy.getScorePerNickName().put( "Johnny", new Integer( 3 ) );
// boy.getScorePerNickName().put( "Thing", new Integer( 5 ) ); boy.getScorePerNickName().put( "Thing", new Integer( 5 ) );
// int[] favNbrs = new int[4]; int[] favNbrs = new int[4];
// for (int index = 0; index < favNbrs.length - 1; index++) { for (int index = 0; index < favNbrs.length - 1; index++) {
// favNbrs[index] = index * 3; favNbrs[index] = index * 3;
// } }
// 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>(); HashMap<String,FavoriteFood> foods = new HashMap<String,FavoriteFood>();
// foods.put( "breakfast", FavoriteFood.PIZZA); foods.put( "breakfast", FavoriteFood.PIZZA);
// foods.put( "lunch", FavoriteFood.KUNGPAOCHICKEN); foods.put( "lunch", FavoriteFood.KUNGPAOCHICKEN);
// foods.put( "dinner", FavoriteFood.SUSHI); foods.put( "dinner", FavoriteFood.SUSHI);
// boy.setFavoriteFood(foods); boy.setFavoriteFood(foods);
// s.persist( boy ); s.persist( boy );
// s.getTransaction().commit(); s.getTransaction().commit();
// s.clear(); s.clear();
// Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
// boy = (Boy) s.get( Boy.class, boy.getId() ); boy = (Boy) s.get( Boy.class, boy.getId() );
// assertNotNull( boy.getNickNames() ); assertNotNull( boy.getNickNames() );
// assertTrue( boy.getNickNames().contains( "Thing" ) ); assertTrue( boy.getNickNames().contains( "Thing" ) );
// assertNotNull( boy.getScorePerNickName() ); assertNotNull( boy.getScorePerNickName() );
// assertTrue( boy.getScorePerNickName().containsKey( "Thing" ) ); assertTrue( boy.getScorePerNickName().containsKey( "Thing" ) );
// assertEquals( new Integer( 5 ), boy.getScorePerNickName().get( "Thing" ) ); assertEquals( new Integer( 5 ), boy.getScorePerNickName().get( "Thing" ) );
// 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("dinner").equals(FavoriteFood.SUSHI));
// assertTrue( boy.getFavoriteFood().get("lunch").equals(FavoriteFood.KUNGPAOCHICKEN)); assertTrue( boy.getFavoriteFood().get("lunch").equals(FavoriteFood.KUNGPAOCHICKEN));
// assertTrue( boy.getFavoriteFood().get("breakfast").equals(FavoriteFood.PIZZA)); 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() );
// s.delete( boy ); s.delete( boy );
// tx.commit(); tx.commit();
// s.close(); s.close();
// } }
@Test @Test
public void testCompositeElement() throws Exception { public void testCompositeElement() throws Exception {
@ -123,166 +122,166 @@ public class CollectionElementTest extends BaseCoreFunctionalTestCase {
boy = (Boy) s.get( Boy.class, boy.getId() ); boy = (Boy) s.get( Boy.class, boy.getId() );
assertNotNull( boy.getFavoriteToys() ); assertNotNull( boy.getFavoriteToys() );
assertTrue( boy.getFavoriteToys().contains( toy ) ); assertTrue( boy.getFavoriteToys().contains( toy ) );
// assertEquals( "@Parent is failing", boy, boy.getFavoriteToys().iterator().next().getOwner() ); assertEquals( "@Parent is failing", boy, boy.getFavoriteToys().iterator().next().getOwner() );
s.delete( boy ); s.delete( boy );
tx.commit(); tx.commit();
s.close(); s.close();
} }
// @Test @Test
// public void testAttributedJoin() throws Exception { public void testAttributedJoin() throws Exception {
// Session s = openSession(); Session s = openSession();
// s.getTransaction().begin(); s.getTransaction().begin();
// Country country = new Country(); Country country = new Country();
// country.setName( "Australia" ); country.setName( "Australia" );
// s.persist( country ); s.persist( country );
//
// Boy boy = new Boy(); Boy boy = new Boy();
// boy.setFirstName( "John" ); boy.setFirstName( "John" );
// boy.setLastName( "Doe" ); boy.setLastName( "Doe" );
// CountryAttitude attitude = new CountryAttitude(); CountryAttitude attitude = new CountryAttitude();
// // TODO: doesn't work // TODO: doesn't work
// attitude.setBoy( boy ); attitude.setBoy( boy );
// attitude.setCountry( country ); attitude.setCountry( country );
// attitude.setLikes( true ); attitude.setLikes( true );
// boy.getCountryAttitudes().add( attitude ); boy.getCountryAttitudes().add( attitude );
// s.persist( boy ); s.persist( boy );
// s.getTransaction().commit(); s.getTransaction().commit();
// s.clear(); s.clear();
//
// Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
// boy = (Boy) s.get( Boy.class, boy.getId() ); boy = (Boy) s.get( Boy.class, boy.getId() );
// assertTrue( boy.getCountryAttitudes().contains( attitude ) ); assertTrue( boy.getCountryAttitudes().contains( attitude ) );
// s.delete( boy ); s.delete( boy );
// s.delete( s.get( Country.class, country.getId() ) ); s.delete( s.get( Country.class, country.getId() ) );
// tx.commit(); tx.commit();
// s.close(); s.close();
// } }
//
// @Test @Test
// public void testLazyCollectionofElements() throws Exception { public void testLazyCollectionofElements() throws Exception {
// assertEquals( assertEquals(
// "BoyFavoriteNumbers", "BoyFavoriteNumbers",
// configuration().getCollectionMapping( Boy.class.getName() + '.' + "favoriteNumbers" ) configuration().getCollectionMapping( Boy.class.getName() + '.' + "favoriteNumbers" )
// .getCollectionTable().getName() .getCollectionTable().getName()
// ); );
// Session s = openSession(); Session s = openSession();
// s.getTransaction().begin(); s.getTransaction().begin();
// Boy boy = new Boy(); Boy boy = new Boy();
// boy.setFirstName( "John" ); boy.setFirstName( "John" );
// boy.setLastName( "Doe" ); boy.setLastName( "Doe" );
// boy.getNickNames().add( "Johnny" ); boy.getNickNames().add( "Johnny" );
// boy.getNickNames().add( "Thing" ); boy.getNickNames().add( "Thing" );
// boy.getScorePerNickName().put( "Johnny", new Integer( 3 ) ); boy.getScorePerNickName().put( "Johnny", new Integer( 3 ) );
// boy.getScorePerNickName().put( "Thing", new Integer( 5 ) ); boy.getScorePerNickName().put( "Thing", new Integer( 5 ) );
// int[] favNbrs = new int[4]; int[] favNbrs = new int[4];
// for (int index = 0; index < favNbrs.length - 1; index++) { for (int index = 0; index < favNbrs.length - 1; index++) {
// favNbrs[index] = index * 3; favNbrs[index] = index * 3;
// } }
// 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 );
// s.persist( boy ); s.persist( boy );
// s.getTransaction().commit(); s.getTransaction().commit();
// s.clear(); s.clear();
// Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
// boy = (Boy) s.get( Boy.class, boy.getId() ); boy = (Boy) s.get( Boy.class, boy.getId() );
// assertNotNull( boy.getNickNames() ); assertNotNull( boy.getNickNames() );
// assertTrue( boy.getNickNames().contains( "Thing" ) ); assertTrue( boy.getNickNames().contains( "Thing" ) );
// assertNotNull( boy.getScorePerNickName() ); assertNotNull( boy.getScorePerNickName() );
// assertTrue( boy.getScorePerNickName().containsKey( "Thing" ) ); assertTrue( boy.getScorePerNickName().containsKey( "Thing" ) );
// assertEquals( new Integer( 5 ), boy.getScorePerNickName().get( "Thing" ) ); assertEquals( new Integer( 5 ), boy.getScorePerNickName().get( "Thing" ) );
// 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 ) );
// 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() );
// s.delete( boy ); s.delete( boy );
// tx.commit(); tx.commit();
// s.close(); s.close();
// } }
//
// @Test @Test
// public void testFetchEagerAndFilter() throws Exception { public void testFetchEagerAndFilter() throws Exception {
// Session s = openSession(); Session s = openSession();
// Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
//
// TestCourse test = new TestCourse(); TestCourse test = new TestCourse();
//
// LocalizedString title = new LocalizedString( "title in english" ); LocalizedString title = new LocalizedString( "title in english" );
// title.getVariations().put( Locale.FRENCH.getLanguage(), "title en francais" ); title.getVariations().put( Locale.FRENCH.getLanguage(), "title en francais" );
// test.setTitle( title ); test.setTitle( title );
// s.save( test ); s.save( test );
//
// s.flush(); s.flush();
// s.clear(); s.clear();
//
// Filter filter = s.enableFilter( "selectedLocale" ); Filter filter = s.enableFilter( "selectedLocale" );
// filter.setParameter( "param", "fr" ); filter.setParameter( "param", "fr" );
//
// Query q = s.createQuery( "from TestCourse t" ); Query q = s.createQuery( "from TestCourse t" );
// List l = q.list(); List l = q.list();
// assertEquals( 1, l.size() ); assertEquals( 1, l.size() );
//
// TestCourse t = (TestCourse) s.get( TestCourse.class, test.getTestCourseId() ); TestCourse t = (TestCourse) s.get( TestCourse.class, test.getTestCourseId() );
// assertEquals( 1, t.getTitle().getVariations().size() ); assertEquals( 1, t.getTitle().getVariations().size() );
//
// tx.rollback(); tx.rollback();
//
// s.close(); s.close();
// } }
//
// @Test @Test
// public void testMapKeyType() throws Exception { public void testMapKeyType() throws Exception {
// Matrix m = new Matrix(); Matrix m = new Matrix();
// m.getMvalues().put( 1, 1.1f ); m.getMvalues().put( 1, 1.1f );
// Session s = openSession(); Session s = openSession();
// Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
// s.persist( m ); s.persist( m );
// s.flush(); s.flush();
// s.clear(); s.clear();
// m = (Matrix) s.get( Matrix.class, m.getId() ); m = (Matrix) s.get( Matrix.class, m.getId() );
// assertEquals( 1.1f, m.getMvalues().get( 1 ), 0.01f ); assertEquals( 1.1f, m.getMvalues().get( 1 ), 0.01f );
// tx.rollback(); tx.rollback();
// s.close(); s.close();
// } }
//
// @Test @Test
// public void testDefaultValueColumnForBasic() throws Exception { public void testDefaultValueColumnForBasic() throws Exception {
// isCollectionColumnPresent( Boy.class.getName(), "hatedNames" ); isCollectionColumnPresent( Boy.class.getName(), "hatedNames" );
// isCollectionColumnPresent( Boy.class.getName(), "preferredNames" ); isCollectionColumnPresent( Boy.class.getName(), "preferredNames" );
// isCollectionColumnPresent( Boy.class.getName(), "nickNames" ); isCollectionColumnPresent( Boy.class.getName(), "nickNames" );
// isCollectionColumnPresent( Boy.class.getName(), "scorePerPreferredName"); isCollectionColumnPresent( Boy.class.getName(), "scorePerPreferredName");
// } }
//
// @Test @Test
// public void testDefaultFKNameForElementCollection() throws Exception { public void testDefaultFKNameForElementCollection() throws Exception {
// isCollectionColumnPresent( Boy.class.getName(), "Boy_id" ); isCollectionColumnPresent( Boy.class.getName(), "Boy_id" );
// } }
//
// private void isCollectionColumnPresent(String collectionOwner, String columnName) { private void isCollectionColumnPresent(String collectionOwner, String columnName) {
// // TODO: Is this correct? Cannot test due to ManyToOne issues. // TODO: Is this correct? Cannot test due to ManyToOne issues.
// Iterator<PluralAttributeBinding> bindings = getCollectionBindings(); Iterator<PluralAttributeBinding> bindings = getCollectionBindings();
// boolean hasDefault = false; boolean hasDefault = false;
// while ( bindings.hasNext() ) { while ( bindings.hasNext() ) {
// PluralAttributeBinding binding = bindings.next(); PluralAttributeBinding binding = bindings.next();
// if ( binding.getAttribute().getName().equals( columnName ) if ( binding.getAttribute().getName().equals( columnName )
// && binding.getAttribute().getAttributeContainer().getClassName().equals( collectionOwner ) ) { && binding.getAttribute().getAttributeContainer().getClassName().equals( collectionOwner ) ) {
// hasDefault = true; hasDefault = true;
// break; break;
// } }
// } }
// assertTrue( "Could not find " + columnName, hasDefault ); assertTrue( "Could not find " + columnName, hasDefault );
// } }
@Override @Override
protected Class[] getAnnotatedClasses() { protected Class[] getAnnotatedClasses() {
return new Class[] { return new Class[] {
Boy.class/*, Boy.class,
Country.class, Country.class,
TestCourse.class, TestCourse.class,
Matrix.class*/ Matrix.class
}; };
} }
} }

View File

@ -14,7 +14,7 @@ public class Toy {
private String name; private String name;
private Brand brand; private Brand brand;
private String serial; private String serial;
// private Boy owner; private Boy owner;
@AttributeOverride(name = "name", column = @Column(name = "brand_name")) @AttributeOverride(name = "name", column = @Column(name = "brand_name"))
public Brand getBrand() { public Brand getBrand() {
@ -41,14 +41,14 @@ public class Toy {
this.serial = serial; this.serial = serial;
} }
// @Parent @Parent
// public Boy getOwner() { public Boy getOwner() {
// return owner; return owner;
// } }
//
// public void setOwner(Boy owner) { public void setOwner(Boy owner) {
// this.owner = owner; this.owner = owner;
// } }
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) return true; if ( this == o ) return true;

View File

@ -23,18 +23,15 @@
*/ */
package org.hibernate.test.annotations.collectionelement.embeddables.withcustomenumdef; package org.hibernate.test.annotations.collectionelement.embeddables.withcustomenumdef;
import org.junit.Test; import static junit.framework.Assert.assertEquals;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@FailureExpectedWithNewMetamodel
public class TestBasicOps extends BaseCoreFunctionalTestCase { public class TestBasicOps extends BaseCoreFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {