mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-19 17:45:10 +00:00
very minor code cleanups in TableBinder
This commit is contained in:
parent
38c8dc90c3
commit
9005403344
@ -37,9 +37,9 @@
|
|||||||
import org.hibernate.mapping.Component;
|
import org.hibernate.mapping.Component;
|
||||||
import org.hibernate.mapping.DependantValue;
|
import org.hibernate.mapping.DependantValue;
|
||||||
import org.hibernate.mapping.JoinedSubclass;
|
import org.hibernate.mapping.JoinedSubclass;
|
||||||
|
import org.hibernate.mapping.KeyValue;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.Selectable;
|
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.mapping.SortableValue;
|
import org.hibernate.mapping.SortableValue;
|
||||||
import org.hibernate.mapping.Table;
|
import org.hibernate.mapping.Table;
|
||||||
@ -532,7 +532,7 @@ public static void bindFk(
|
|||||||
SimpleValue value,
|
SimpleValue value,
|
||||||
boolean unique,
|
boolean unique,
|
||||||
MetadataBuildingContext buildingContext) {
|
MetadataBuildingContext buildingContext) {
|
||||||
PersistentClass associatedClass;
|
final PersistentClass associatedClass;
|
||||||
if ( destinationEntity != null ) {
|
if ( destinationEntity != null ) {
|
||||||
//overridden destination
|
//overridden destination
|
||||||
associatedClass = destinationEntity;
|
associatedClass = destinationEntity;
|
||||||
@ -550,11 +550,10 @@ public static void bindFk(
|
|||||||
*/
|
*/
|
||||||
LOG.debugf( "Retrieving property %s.%s", associatedClass.getEntityName(), mappedByProperty );
|
LOG.debugf( "Retrieving property %s.%s", associatedClass.getEntityName(), mappedByProperty );
|
||||||
|
|
||||||
final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() );
|
final Value propertyVal = associatedClass.getRecursiveProperty( columns[0].getMappedBy() ).getValue();
|
||||||
List<Column> mappedByColumns;
|
final List<Column> mappedByColumns;
|
||||||
if ( property.getValue() instanceof Collection ) {
|
if ( propertyVal instanceof Collection ) {
|
||||||
Collection collection = ( (Collection) property.getValue() );
|
Value element = ((Collection) propertyVal).getElement();
|
||||||
Value element = collection.getElement();
|
|
||||||
if ( element == null ) {
|
if ( element == null ) {
|
||||||
throw new AnnotationException(
|
throw new AnnotationException(
|
||||||
"Illegal use of mappedBy on both sides of the relationship: "
|
"Illegal use of mappedBy on both sides of the relationship: "
|
||||||
@ -564,7 +563,7 @@ public static void bindFk(
|
|||||||
mappedByColumns = element.getColumns();
|
mappedByColumns = element.getColumns();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mappedByColumns = property.getValue().getColumns();
|
mappedByColumns = propertyVal.getColumns();
|
||||||
}
|
}
|
||||||
for ( Column column: mappedByColumns ) {
|
for ( Column column: mappedByColumns ) {
|
||||||
columns[0].overrideFromReferencedColumnIfNecessary( column );
|
columns[0].overrideFromReferencedColumnIfNecessary( column );
|
||||||
@ -586,7 +585,6 @@ else if ( columns[0].isImplicit() ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int fkEnum = AnnotatedJoinColumn.checkReferencedColumnsType( columns, referencedEntity, buildingContext );
|
int fkEnum = AnnotatedJoinColumn.checkReferencedColumnsType( columns, referencedEntity, buildingContext );
|
||||||
|
|
||||||
if ( AnnotatedJoinColumn.NON_PK_REFERENCE == fkEnum ) {
|
if ( AnnotatedJoinColumn.NON_PK_REFERENCE == fkEnum ) {
|
||||||
String referencedPropertyName;
|
String referencedPropertyName;
|
||||||
if ( value instanceof ToOne ) {
|
if ( value instanceof ToOne ) {
|
||||||
@ -651,26 +649,26 @@ else if ( value instanceof DependantValue ) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Ensure the component is sorted so that we can simply set sorted to true on the to-one
|
// Ensure the component is sorted so that we can simply set sorted to true on the to-one
|
||||||
if ( referencedEntity.getKey() instanceof Component ) {
|
KeyValue key = referencedEntity.getKey();
|
||||||
( (Component) referencedEntity.getKey() ).sortProperties();
|
if ( key instanceof Component ) {
|
||||||
|
( (Component) key).sortProperties();
|
||||||
}
|
}
|
||||||
//explicit referencedColumnName
|
//explicit referencedColumnName
|
||||||
List<Column> idColumns = referencedEntity.getKey().getColumns();
|
List<Column> idColumns = key.getColumns();
|
||||||
//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 ( idColumns.isEmpty() ) {
|
if ( idColumns.isEmpty() ) {
|
||||||
LOG.debug( "No column in the identifier" );
|
LOG.debug( "No column in the identifier" );
|
||||||
}
|
}
|
||||||
|
final Dialect dialect = buildingContext.getMetadataCollector().getDatabase()
|
||||||
|
.getJdbcEnvironment().getDialect();
|
||||||
for ( Column col: idColumns ) {
|
for ( Column col: idColumns ) {
|
||||||
boolean match = false;
|
boolean match = false;
|
||||||
//for each PK column, find the associated FK column.
|
//for each PK column, find the associated FK column.
|
||||||
Dialect dialect = buildingContext.getMetadataCollector().getDatabase()
|
|
||||||
.getJdbcEnvironment().getDialect();
|
|
||||||
final String colName = col.getQuotedName(dialect);
|
final String colName = col.getQuotedName(dialect);
|
||||||
for (AnnotatedJoinColumn joinCol : columns) {
|
for (AnnotatedJoinColumn joinCol : columns) {
|
||||||
String referencedColumn = joinCol.getReferencedColumn();
|
String referencedColumn = joinCol.getReferencedColumn();
|
||||||
referencedColumn = buildingContext.getMetadataCollector().getPhysicalColumnName(
|
referencedColumn = buildingContext.getMetadataCollector().getPhysicalColumnName(
|
||||||
table,
|
referencedEntity.getTable(),
|
||||||
referencedColumn
|
referencedColumn
|
||||||
);
|
);
|
||||||
//In JPA 2 referencedColumnName is case-insensitive
|
//In JPA 2 referencedColumnName is case-insensitive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user