HHH-10978 - Fix building join table metadata with default catalogs or schema values.

(cherry picked from commit 1dcb391f83)

Conflicts:
	hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java
	hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
This commit is contained in:
Chris Cranford 2016-08-09 19:01:45 -05:00 committed by Gail Badner
parent c60287264f
commit 4a60011cb7
2 changed files with 57 additions and 24 deletions

View File

@ -237,7 +237,9 @@ public class BinderHelper {
boolean inverse, boolean inverse,
MetadataBuildingContext context) { MetadataBuildingContext context) {
//associated entity only used for more precise exception, yuk! //associated entity only used for more precise exception, yuk!
if ( columns[0].isImplicit() || StringHelper.isNotEmpty( columns[0].getMappedBy() ) ) return; if ( columns[0].isImplicit() || StringHelper.isNotEmpty( columns[0].getMappedBy() ) ) {
return;
}
int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, ownerEntity, context ); int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, ownerEntity, context );
PersistentClass associatedClass = columns[0].getPropertyHolder() != null ? PersistentClass associatedClass = columns[0].getPropertyHolder() != null ?
columns[0].getPropertyHolder().getPersistentClass() : columns[0].getPropertyHolder().getPersistentClass() :
@ -407,13 +409,18 @@ public class BinderHelper {
break; break;
} }
} }
if ( !found ) return null; //have to find it the hard way if ( !found ) {
//have to find it the hard way
return null;
}
} }
return orderedProperties; return orderedProperties;
} }
private static void matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty) { private static void matchColumnsByProperty(Property property, Map<Column, Set<Property>> columnsToProperty) {
if ( property == null ) return; if ( property == null ) {
return;
}
if ( "noop".equals( property.getPropertyAccessorName() ) if ( "noop".equals( property.getPropertyAccessorName() )
|| "embedded".equals( property.getPropertyAccessorName() ) ) { || "embedded".equals( property.getPropertyAccessorName() ) ) {
return; return;
@ -428,7 +435,8 @@ public class BinderHelper {
else { else {
Iterator columnIt = property.getColumnIterator(); Iterator columnIt = property.getColumnIterator();
while ( columnIt.hasNext() ) { while ( columnIt.hasNext() ) {
Object column = columnIt.next(); //can be a Formula so we don't cast //can be a Formula so we don't cast
Object column = columnIt.next();
//noinspection SuspiciousMethodCalls //noinspection SuspiciousMethodCalls
if ( columnsToProperty.containsKey( column ) ) { if ( columnsToProperty.containsKey( column ) ) {
columnsToProperty.get( column ).add( property ); columnsToProperty.get( column ).add( property );
@ -464,7 +472,9 @@ public class BinderHelper {
property = associatedClass.getProperty( element ); property = associatedClass.getProperty( element );
} }
else { else {
if ( !property.isComposite() ) return null; if ( !property.isComposite() ) {
return null;
}
property = ( (Component) property.getValue() ).getProperty( element ); property = ( (Component) property.getValue() ).getProperty( element );
} }
} }
@ -473,7 +483,9 @@ public class BinderHelper {
catch (MappingException e) { catch (MappingException e) {
try { try {
//if we do not find it try to check the identifier mapper //if we do not find it try to check the identifier mapper
if ( associatedClass.getIdentifierMapper() == null ) return null; if ( associatedClass.getIdentifierMapper() == null ) {
return null;
}
StringTokenizer st = new StringTokenizer( propertyName, ".", false ); StringTokenizer st = new StringTokenizer( propertyName, ".", false );
while ( st.hasMoreElements() ) { while ( st.hasMoreElements() ) {
String element = (String) st.nextElement(); String element = (String) st.nextElement();
@ -481,7 +493,9 @@ public class BinderHelper {
property = associatedClass.getIdentifierMapper().getProperty( element ); property = associatedClass.getIdentifierMapper().getProperty( element );
} }
else { else {
if ( !property.isComposite() ) return null; if ( !property.isComposite() ) {
return null;
}
property = ( (Component) property.getValue() ).getProperty( element ); property = ( (Component) property.getValue() ).getProperty( element );
} }
} }
@ -512,7 +526,9 @@ public class BinderHelper {
property = component.getProperty( element ); property = component.getProperty( element );
} }
else { else {
if ( !property.isComposite() ) return null; if ( !property.isComposite() ) {
return null;
}
property = ( (Component) property.getValue() ).getProperty( element ); property = ( (Component) property.getValue() ).getProperty( element );
} }
} }
@ -521,7 +537,9 @@ public class BinderHelper {
catch (MappingException e) { catch (MappingException e) {
try { try {
//if we do not find it try to check the identifier mapper //if we do not find it try to check the identifier mapper
if ( component.getOwner().getIdentifierMapper() == null ) return null; if ( component.getOwner().getIdentifierMapper() == null ) {
return null;
}
StringTokenizer st = new StringTokenizer( propertyName, ".", false ); StringTokenizer st = new StringTokenizer( propertyName, ".", false );
while ( st.hasMoreElements() ) { while ( st.hasMoreElements() ) {
String element = (String) st.nextElement(); String element = (String) st.nextElement();
@ -529,7 +547,9 @@ public class BinderHelper {
property = component.getOwner().getIdentifierMapper().getProperty( element ); property = component.getOwner().getIdentifierMapper().getProperty( element );
} }
else { else {
if ( !property.isComposite() ) return null; if ( !property.isComposite() ) {
return null;
}
property = ( (Component) property.getValue() ).getProperty( element ); property = ( (Component) property.getValue() ).getProperty( element );
} }
} }
@ -542,7 +562,9 @@ public class BinderHelper {
} }
public static String getRelativePath(PropertyHolder propertyHolder, String propertyName) { public static String getRelativePath(PropertyHolder propertyHolder, String propertyName) {
if ( propertyHolder == null ) return propertyName; if ( propertyHolder == null ) {
return propertyName;
}
String path = propertyHolder.getPath(); String path = propertyHolder.getPath();
String entityName = propertyHolder.getPersistentClass().getEntityName(); String entityName = propertyHolder.getPersistentClass().getEntityName();
if ( path.length() == entityName.length() ) { if ( path.length() == entityName.length() ) {
@ -562,7 +584,8 @@ public class BinderHelper {
String columnName, String columnName,
MetadataBuildingContext context) { MetadataBuildingContext context) {
if ( StringHelper.isEmpty( columnName ) ) { if ( StringHelper.isEmpty( columnName ) ) {
return persistentClass; //shortcut for implicit referenced column names //shortcut for implicit referenced column names
return persistentClass;
} }
PersistentClass current = persistentClass; PersistentClass current = persistentClass;
Object result; Object result;
@ -656,7 +679,9 @@ public class BinderHelper {
params.setProperty( (String) elt.getKey(), (String) elt.getValue() ); params.setProperty( (String) elt.getKey(), (String) elt.getValue() );
} }
} }
if ( "assigned".equals( generatorType ) ) id.setNullValue( "undefined" ); if ( "assigned".equals( generatorType ) ) {
id.setNullValue( "undefined" );
}
id.setIdentifierGeneratorProperties( params ); id.setIdentifierGeneratorProperties( params );
} }
@ -679,6 +704,10 @@ public class BinderHelper {
//equivalent to (but faster) ANNOTATION_STRING_DEFAULT.equals( annotationString ); //equivalent to (but faster) ANNOTATION_STRING_DEFAULT.equals( annotationString );
} }
public static boolean isEmptyOrNullAnnotationValue(String annotationString) {
return annotationString == null || annotationString.length() == 0;
}
public static Any buildAnyValue( public static Any buildAnyValue(
String anyMetaDefName, String anyMetaDefName,
Ejb3JoinColumn[] columns, Ejb3JoinColumn[] columns,
@ -722,7 +751,9 @@ public class BinderHelper {
throw new MappingException( "could not interpret metaValue", e ); throw new MappingException( "could not interpret metaValue", e );
} }
} }
if ( !values.isEmpty() ) value.setMetaValues( values ); if ( !values.isEmpty() ) {
value.setMetaValues( values );
}
} }
else { else {
throw new AnnotationException( "Unable to find @AnyMetaDef for an @(ManyTo)Any mapping: " throw new AnnotationException( "Unable to find @AnyMetaDef for an @(ManyTo)Any mapping: "
@ -792,7 +823,8 @@ public class BinderHelper {
private static void bindAnyMetaDef(AnyMetaDef defAnn, MetadataBuildingContext context) { private static void bindAnyMetaDef(AnyMetaDef defAnn, MetadataBuildingContext context) {
if ( isEmptyAnnotationValue( defAnn.name() ) ) { if ( isEmptyAnnotationValue( defAnn.name() ) ) {
return; //don't map not named definitions //don't map not named definitions
return;
} }
if ( LOG.isDebugEnabled() ) { if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Binding Any Meta definition: %s", defAnn.name() ); LOG.debugf( "Binding Any Meta definition: %s", defAnn.name() );

View File

@ -487,10 +487,10 @@ public class TableBinder {
MetadataBuildingContext buildingContext, MetadataBuildingContext buildingContext,
String subselect, String subselect,
InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) { InFlightMetadataCollector.EntityTableXref denormalizedSuperTableXref) {
schema = BinderHelper.isEmptyAnnotationValue( schema ) schema = BinderHelper.isEmptyOrNullAnnotationValue( schema )
? extract( buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getSchema() ) ? extract( buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getSchema() )
: schema; : schema;
catalog = BinderHelper.isEmptyAnnotationValue( catalog ) catalog = BinderHelper.isEmptyOrNullAnnotationValue( catalog )
? extract( buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getCatalog() ) ? extract( buildingContext.getMetadataCollector().getDatabase().getDefaultNamespace().getPhysicalName().getCatalog() )
: catalog; : catalog;
@ -668,7 +668,8 @@ public class TableBinder {
//explicit referencedColumnName //explicit referencedColumnName
Iterator idColItr = referencedEntity.getKey().getColumnIterator(); Iterator idColItr = referencedEntity.getKey().getColumnIterator();
org.hibernate.mapping.Column col; org.hibernate.mapping.Column col;
Table table = referencedEntity.getTable(); //works cause the pk has to be on the primary table //works cause the pk has to be on the primary table
Table table = referencedEntity.getTable();
if ( !idColItr.hasNext() ) { if ( !idColItr.hasNext() ) {
LOG.debug( "No column in the identifier!" ); LOG.debug( "No column in the identifier!" );
} }