HHH-4682 Check that @CollectionTable (or its absence) defaults to the right table/column names

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18392 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Scott Marlow 2010-01-04 16:03:21 +00:00
parent 763a3ef84b
commit 41b12a6479
2 changed files with 76 additions and 0 deletions

View File

@ -365,6 +365,50 @@ public class EmbeddedTest extends TestCase {
s.close();
}
// quick test based on testSimple
public void testCollectionTable() throws Exception {
Session s;
Transaction tx;
WealthyPerson p = new WealthyPerson();
Address a = new Address();
Address vacation = new Address();
Country c = new Country();
Country bornCountry = new Country();
c.setIso2( "DM" );
c.setName( "Matt Damon Land" );
bornCountry.setIso2( "US" );
bornCountry.setName( "United States of America" );
a.address1 = "colorado street";
a.city = "Springfield";
a.country = c;
vacation.address1 = "rock street";
vacation.city = "Plymouth";
vacation.country = c;
p.vacationHomes.add(vacation);
p.address = a;
p.bornIn = bornCountry;
p.name = "Homer";
s = openSession();
tx = s.beginTransaction();
s.persist( p );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
p = (WealthyPerson) s.get( WealthyPerson.class, p.id );
assertNotNull( p );
assertNotNull( p.address );
assertEquals( "Springfield", p.address.city );
assertNotNull( p.address.country );
assertEquals( "DM", p.address.country.getIso2() );
assertNotNull( p.bornIn );
assertEquals( "US", p.bornIn.getIso2() );
tx.commit();
s.close();
}
public EmbeddedTest(String x) {
super( x );
}
@ -372,6 +416,7 @@ public class EmbeddedTest extends TestCase {
protected Class[] getMappings() {
return new Class[]{
Person.class,
WealthyPerson.class,
RegionalArticle.class,
AddressType.class,
VanillaSwap.class,

View File

@ -0,0 +1,31 @@
package org.hibernate.test.annotations.embedded;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
@Entity
public class WealthyPerson extends Person {
@ElementCollection
@CollectionTable(name="XXXHOMES")
@AttributeOverrides({
@AttributeOverride(name="address1",
column=@Column(name="HOME_STREET")),
@AttributeOverride(name="city",
column=@Column(name="HOME_CITY")),
@AttributeOverride(name="country",
column=@Column(name="HOME_COUNTRY"))
})
protected Set<Address> vacationHomes = new HashSet();
}