From 9f8f07c22951e6a60481b40686de12a936d2c6de Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 9 Jul 2014 15:08:21 -0700 Subject: [PATCH] HHH-9280 : Table name generated for @ElementCollection uses owning entity class name instead of mapped entity name (cherry picked from commit ccffe0dea9d9d4aae05ffaaa9239ff5ac5b3346a) --- .../org/hibernate/cfg/annotations/CollectionBinder.java | 2 +- .../collectionelement/CollectionElementTest.java | 8 ++++++++ .../test/annotations/collectionelement/Matrix.java | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java index 6615d11c09..44dca23880 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java @@ -1140,7 +1140,7 @@ else if ( anyAnn != null ) { if ( StringHelper.isEmpty( associationTableBinder.getName() ) ) { //default value associationTableBinder.setDefaultName( - collValue.getOwner().getEntityName(), + collValue.getOwner().getJpaEntityName(), mappings.getLogicalTableName( collValue.getOwner().getTable() ), collectionEntity != null ? collectionEntity.getEntityName() : null, collectionEntity != null ? mappings.getLogicalTableName( collectionEntity.getTable() ) : null, diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java index 0795794bff..b3cae24462 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/CollectionElementTest.java @@ -36,6 +36,7 @@ import org.hibernate.Transaction; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; +import org.hibernate.mapping.Table; import org.hibernate.test.annotations.Country; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -260,6 +261,13 @@ public void testDefaultFKNameForElementCollection() throws Exception { isCollectionColumnPresent( Boy.class.getName(), "hatedNames", "Boy_id" ); } + @Test + public void testDefaultTableNameUsesJpaEntityName() { + final Collection collection = configuration().getCollectionMapping( Matrix.class.getName() + "." + "mvalues" ); + final Table table = collection.getCollectionTable(); + assertEquals( "Mtx_mvalues", table.getName() ); + } + private void isLegacyValueCollectionColumnPresent(String collectionHolder, String propertyName) { } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java index 09a4828451..84d719b5f1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java @@ -17,7 +17,7 @@ /** * @author Emmanuel Bernard */ -@Entity +@Entity(name="Mtx") public class Matrix { @Id @GeneratedValue