From 5509ab643d2e0ea738899d6d089eff425fd4021e Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Tue, 5 Jan 2010 18:50:48 +0000 Subject: [PATCH] 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 --- .../entity/BasicHibernateAnnotationsTest.java | 25 ++++++++++++++++++- .../test/annotations/entity/Forest.java | 15 +++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java b/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java index 71e1e4ba00..d5b40ead5a 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java @@ -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 near = new HashSet(); + 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(); } diff --git a/annotations/src/test/java/org/hibernate/test/annotations/entity/Forest.java b/annotations/src/test/java/org/hibernate/test/annotations/entity/Forest.java index 49c90ea998..68bcbaae23 100644 --- a/annotations/src/test/java/org/hibernate/test/annotations/entity/Forest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/entity/Forest.java @@ -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 getNear() { + return near; + } + + public void setNear(Setnear) { + this.near = near; + } + }