Author: epbernard
Date: 2010-01-05 11:11:14 -0500 (Tue, 05 Jan 2010)
New Revision: 18413
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/WealthyPerson.java
Log:
HHH-4753 Default table name for @CollectionTable is not inferred correctly according to
spec requirement. Legacy names still supported.
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java 2010-01-05
14:06:38 UTC (rev 18412)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java 2010-01-05
16:11:14 UTC (rev 18413)
@@ -1225,6 +1225,7 @@
joinColumns[0].getPropertyName()
);
}
+ associationTableBinder.setJPA2ElementCollection( !isCollectionOfEntities &&
property.isAnnotationPresent( ElementCollection.class ));
collValue.setCollectionTable( associationTableBinder.bind() );
}
bindFilters( isCollectionOfEntities );
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java 2010-01-05
14:06:38 UTC (rev 18412)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java 2010-01-05
16:11:14 UTC (rev 18413)
@@ -77,6 +77,7 @@
private String propertyName;
private String ownerEntity;
private String associatedEntity;
+ private boolean isJPA2ElementCollection;
public void setSchema(String schema) {
this.schema = schema;
@@ -114,6 +115,10 @@
this.mappings = mappings;
}
+ public void setJPA2ElementCollection(boolean isJPA2ElementCollection) {
+ this.isJPA2ElementCollection = isJPA2ElementCollection;
+ }
+
private static class AssociationTableNameSource implements ObjectNameSource {
private final String explicitName;
private final String logicalName;
@@ -138,15 +143,20 @@
final String unquotedOwnerTable = StringHelper.unquote( ownerEntityTable );
final String unquotedAssocTable = StringHelper.unquote( associatedEntityTable );
- final ObjectNameSource nameSource = buildNameContext( unquotedOwnerTable,
unquotedAssocTable );
+ //@ElementCollection use ownerEntity_property instead of the cleaner
ownerTableName_property
+ final String ownerObjectName = isJPA2ElementCollection ? StringHelper.unqualify(
ownerEntity ) : unquotedOwnerTable;
+ final ObjectNameSource nameSource = buildNameContext(
+ ownerObjectName,
+ unquotedAssocTable );
final boolean ownerEntityTableQuoted = StringHelper.isQuoted( ownerEntityTable );
final boolean associatedEntityTableQuoted = StringHelper.isQuoted(
associatedEntityTable );
final ObjectNameNormalizer.NamingStrategyHelper namingStrategyHelper = new
ObjectNameNormalizer.NamingStrategyHelper() {
public String determineImplicitName(NamingStrategy strategy) {
+
final String strategyResult = strategy.collectionTableName(
ownerEntity,
- unquotedOwnerTable,
+ ownerObjectName,
associatedEntity,
unquotedAssocTable,
propertyName
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java 2010-01-05
14:06:38 UTC (rev 18412)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java 2010-01-05
16:11:14 UTC (rev 18413)
@@ -11,6 +11,7 @@
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.annotations.embedded.FloatLeg.RateIndex;
import org.hibernate.test.annotations.embedded.Leg.Frequency;
+import org.hibernate.test.util.SchemaUtil;
/**
* @author Emmanuel Bernard
@@ -365,8 +366,13 @@
s.close();
}
- // quick test based on testSimple
- public void testCollectionTable() throws Exception {
+ public void testDefaultCollectionTable() throws Exception {
+ //are the tables correct?
+ assertTrue( SchemaUtil.isTablePresent("WealthyPerson_vacationHomes", getCfg()
) );
+ assertTrue( SchemaUtil.isTablePresent("PersonEmbed_legacyVacationHomes",
getCfg() ) );
+ assertTrue( SchemaUtil.isTablePresent("WelPers_VacHomes", getCfg() ) );
+
+ //just to make sure, use the mapping
Session s;
Transaction tx;
WealthyPerson p = new WealthyPerson();
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/WealthyPerson.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/WealthyPerson.java 2010-01-05
14:06:38 UTC (rev 18412)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/embedded/WealthyPerson.java 2010-01-05
16:11:14 UTC (rev 18413)
@@ -14,18 +14,27 @@
import java.util.HashSet;
import java.util.Set;
+import org.hibernate.annotations.CollectionOfElements;
+
@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"))
- })
+// @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<Address>();
+
+ @CollectionOfElements
+ protected Set<Address> legacyVacationHomes = new HashSet<Address>();
+
+ @CollectionOfElements
+ @CollectionTable(name = "WelPers_VacHomes")
+ protected Set<Address> explicitVacationHomes = new HashSet<Address>();
}
Show replies by date