HHH-4684 Make sure @Lob works with @ElementCollection
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18416 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
39dd795e40
commit
5509ab643d
|
@ -27,6 +27,9 @@ package org.hibernate.test.annotations.entity;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.Currency;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.Hibernate;
|
||||
|
@ -469,6 +472,17 @@ public class BasicHibernateAnnotationsTest extends TestCase {
|
|||
Country country = new Country();
|
||||
country.setName( "Middle Earth" );
|
||||
forest.setCountry( country );
|
||||
Set<Country> near = new HashSet<Country>();
|
||||
country = new Country();
|
||||
country.setName("Mordor");
|
||||
near.add(country);
|
||||
country = new Country();
|
||||
country.setName("Gondor");
|
||||
near.add(country);
|
||||
country = new Country();
|
||||
country.setName("Eriador");
|
||||
near.add(country);
|
||||
forest.setNear(near);
|
||||
Session s;
|
||||
Transaction tx;
|
||||
s = openSession();
|
||||
|
@ -481,8 +495,17 @@ public class BasicHibernateAnnotationsTest extends TestCase {
|
|||
tx = s.beginTransaction();
|
||||
forest = (Forest) s.get( Forest.class, forest.getId() );
|
||||
assertNotNull( forest );
|
||||
assertNotNull( forest.getCountry() );
|
||||
country = forest.getCountry();
|
||||
assertNotNull( country );
|
||||
assertEquals( country.getName(), forest.getCountry().getName() );
|
||||
near = forest.getNear();
|
||||
assertTrue("correct number of nearby countries", near.size() == 3);
|
||||
for (Iterator iter = near.iterator(); iter.hasNext();) {
|
||||
country = (Country)iter.next();
|
||||
String name = country.getName();
|
||||
assertTrue("found expected nearby country " + name,
|
||||
(name.equals("Mordor") || name.equals("Gondor") || name.equals("Eriador")));
|
||||
}
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//$Id$
|
||||
package org.hibernate.test.annotations.entity;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
@ -19,6 +20,8 @@ import org.hibernate.annotations.PolymorphismType;
|
|||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.annotations.Where;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Use hibernate specific annotations
|
||||
*
|
||||
|
@ -47,6 +50,7 @@ public class Forest {
|
|||
private String smallText;
|
||||
private String bigText;
|
||||
private Country country;
|
||||
private Set near;
|
||||
|
||||
@OptimisticLock(excluded=true)
|
||||
@Type(type = "text")
|
||||
|
@ -110,4 +114,15 @@ public class Forest {
|
|||
public void setCountry(Country country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
@Lob
|
||||
@ElementCollection
|
||||
public Set<Country> getNear() {
|
||||
return near;
|
||||
}
|
||||
|
||||
public void setNear(Set<Country>near) {
|
||||
this.near = near;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue