HHH-4753 Default table name for @CollectionTable is not inferred correctly according to spec requirement. Legacy names still supported.
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18413 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
dd7b01ccc8
commit
76202814a6
|
@ -1225,6 +1225,7 @@ public abstract class CollectionBinder {
|
|||
joinColumns[0].getPropertyName()
|
||||
);
|
||||
}
|
||||
associationTableBinder.setJPA2ElementCollection( !isCollectionOfEntities && property.isAnnotationPresent( ElementCollection.class ));
|
||||
collValue.setCollectionTable( associationTableBinder.bind() );
|
||||
}
|
||||
bindFilters( isCollectionOfEntities );
|
||||
|
|
|
@ -77,6 +77,7 @@ public class TableBinder {
|
|||
private String propertyName;
|
||||
private String ownerEntity;
|
||||
private String associatedEntity;
|
||||
private boolean isJPA2ElementCollection;
|
||||
|
||||
public void setSchema(String schema) {
|
||||
this.schema = schema;
|
||||
|
@ -114,6 +115,10 @@ public class TableBinder {
|
|||
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 @@ public class TableBinder {
|
|||
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
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.Transaction;
|
|||
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 @@ public class EmbeddedTest extends TestCase {
|
|||
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();
|
||||
|
|
|
@ -14,18 +14,27 @@ import java.io.Serializable;
|
|||
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>();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue