finally move propertyName from AnnotatedColumn
This commit is contained in:
parent
e4c1d493e3
commit
849246e3cd
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.cfg;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
|
@ -44,7 +43,6 @@ import static org.hibernate.cfg.BinderHelper.isEmptyAnnotationValue;
|
|||
import static org.hibernate.internal.util.StringHelper.isEmpty;
|
||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
||||
import static org.hibernate.internal.util.StringHelper.qualify;
|
||||
|
||||
/**
|
||||
* A mapping to a column, logically representing a
|
||||
|
@ -75,7 +73,6 @@ public class AnnotatedColumn {
|
|||
private Integer precision;
|
||||
private Integer scale;
|
||||
private String logicalColumnName;
|
||||
private String propertyName; // this is really a .-separated property path
|
||||
private boolean unique;
|
||||
private boolean nullable = true;
|
||||
private String formulaString;
|
||||
|
@ -180,17 +177,6 @@ public class AnnotatedColumn {
|
|||
this.logicalColumnName = logicalColumnName;
|
||||
}
|
||||
|
||||
public void setPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* A property path relative to the {@link #getPropertyHolder() PropertyHolder}.
|
||||
*/
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
@ -243,7 +229,7 @@ public class AnnotatedColumn {
|
|||
else {
|
||||
initMappingColumn(
|
||||
logicalColumnName,
|
||||
propertyName,
|
||||
getParent().getPropertyName(),
|
||||
length,
|
||||
precision,
|
||||
scale,
|
||||
|
@ -361,8 +347,8 @@ public class AnnotatedColumn {
|
|||
public boolean isCollectionElement() {
|
||||
// if the propertyHolder is a collection, assume the
|
||||
// @Column refers to the element column
|
||||
return !getPropertyHolder().isComponent()
|
||||
&& !getPropertyHolder().isEntity();
|
||||
final PropertyHolder propertyHolder = getParent().getPropertyHolder();
|
||||
return !propertyHolder.isComponent() && !propertyHolder.isEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -409,10 +395,6 @@ public class AnnotatedColumn {
|
|||
}
|
||||
}
|
||||
|
||||
public PropertyHolder getPropertyHolder() {
|
||||
return getParent().getPropertyHolder();
|
||||
}
|
||||
|
||||
protected void setMappingColumn(Column mappingColumn) {
|
||||
this.mappingColumn = mappingColumn;
|
||||
}
|
||||
|
@ -450,7 +432,7 @@ public class AnnotatedColumn {
|
|||
new ImplicitBasicColumnNameSource() {
|
||||
@Override
|
||||
public AttributePath getAttributePath() {
|
||||
return AttributePath.parse( propertyName );
|
||||
return AttributePath.parse( getParent().getPropertyName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -470,27 +452,6 @@ public class AnnotatedColumn {
|
|||
getBuildingContext().getMetadataCollector().addColumnNameBinding( value.getTable(), logicalColumnName, getMappingColumn() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find appropriate table of the column.
|
||||
* It can come from a secondary table or from the main table of the persistent class
|
||||
*
|
||||
* @return appropriate table
|
||||
* @throws AnnotationException missing secondary table
|
||||
*/
|
||||
public Table getTable() {
|
||||
return getParent().getTable();
|
||||
}
|
||||
|
||||
//TODO: move to AnnotatedColumns
|
||||
public boolean isSecondary() {
|
||||
return getParent().isSecondary();
|
||||
}
|
||||
|
||||
//TODO: move to AnnotatedColumns
|
||||
public Join getJoin() {
|
||||
return getParent().getJoin();
|
||||
}
|
||||
|
||||
public void forceNotNull() {
|
||||
if ( mappingColumn == null ) {
|
||||
throw new CannotForceNonNullableException(
|
||||
|
@ -639,6 +600,7 @@ public class AnnotatedColumn {
|
|||
if ( formulaAnn != null ) {
|
||||
final AnnotatedColumns parent = new AnnotatedColumns();
|
||||
parent.setPropertyHolder( propertyHolder );
|
||||
parent.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
|
||||
parent.setBuildingContext( context );
|
||||
parent.setJoins( secondaryTables ); //unnecessary
|
||||
final AnnotatedColumn formulaColumn = new AnnotatedColumn();
|
||||
|
@ -681,15 +643,14 @@ public class AnnotatedColumn {
|
|||
jakarta.persistence.Column[] columns,
|
||||
PropertyHolder propertyHolder,
|
||||
PropertyData inferredData ) {
|
||||
final jakarta.persistence.Column[] overriddenCols = propertyHolder.getOverriddenColumn(
|
||||
qualify( propertyHolder.getPath(), inferredData.getPropertyName() )
|
||||
);
|
||||
final String path = getPath( propertyHolder, inferredData );
|
||||
final jakarta.persistence.Column[] overriddenCols = propertyHolder.getOverriddenColumn( path );
|
||||
if ( overriddenCols != null ) {
|
||||
//check for overridden first
|
||||
if ( columns != null && overriddenCols.length != columns.length ) {
|
||||
//TODO: unfortunately, we never actually see this nice error message, since
|
||||
// PersistentClass.validate() gets called first and produces a worse message
|
||||
throw new AnnotationException( "Property '" + getPath( propertyHolder, inferredData )
|
||||
throw new AnnotationException( "Property '" + path
|
||||
+ "' specifies " + columns.length
|
||||
+ " '@AttributeOverride's but the overridden property has " + overriddenCols.length
|
||||
+ " columns (every column must have exactly one '@AttributeOverride')" );
|
||||
|
@ -712,6 +673,7 @@ public class AnnotatedColumn {
|
|||
jakarta.persistence.Column[] actualCols) {
|
||||
final AnnotatedColumns parent = new AnnotatedColumns();
|
||||
parent.setPropertyHolder( propertyHolder );
|
||||
parent.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
|
||||
parent.setJoins( secondaryTables );
|
||||
parent.setBuildingContext( context );
|
||||
for ( jakarta.persistence.Column column : actualCols ) {
|
||||
|
@ -760,7 +722,7 @@ public class AnnotatedColumn {
|
|||
jakarta.persistence.Column column,
|
||||
String sqlType,
|
||||
String tableName) {
|
||||
final String columnName = getLogicalColumnName( inferredData, suffixForDefaultColumnName, database, column );
|
||||
final String columnName = logicalColumnName( inferredData, suffixForDefaultColumnName, database, column );
|
||||
final AnnotatedColumn annotatedColumn = new AnnotatedColumn();
|
||||
annotatedColumn.setLogicalColumnName( columnName );
|
||||
annotatedColumn.setImplicit( false );
|
||||
|
@ -769,7 +731,7 @@ public class AnnotatedColumn {
|
|||
annotatedColumn.setPrecision( column.precision() );
|
||||
annotatedColumn.setScale( column.scale() );
|
||||
// annotatedColumn.setPropertyHolder( propertyHolder );
|
||||
annotatedColumn.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
|
||||
// annotatedColumn.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
|
||||
annotatedColumn.setNullable( column.nullable() ); //TODO force to not null if available? This is a (bad) user choice.
|
||||
if ( comment != null ) {
|
||||
annotatedColumn.setComment( comment.value() );
|
||||
|
@ -789,7 +751,7 @@ public class AnnotatedColumn {
|
|||
return annotatedColumn;
|
||||
}
|
||||
|
||||
private static String getLogicalColumnName(
|
||||
private static String logicalColumnName(
|
||||
PropertyData inferredData,
|
||||
String suffixForDefaultColumnName,
|
||||
Database database,
|
||||
|
@ -896,6 +858,7 @@ public class AnnotatedColumn {
|
|||
MetadataBuildingContext context) {
|
||||
final AnnotatedColumns columns = new AnnotatedColumns();
|
||||
columns.setPropertyHolder( propertyHolder );
|
||||
columns.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
|
||||
columns.setBuildingContext( context );
|
||||
columns.setJoins( secondaryTables );
|
||||
columns.setPropertyHolder( propertyHolder );
|
||||
|
@ -911,7 +874,7 @@ public class AnnotatedColumn {
|
|||
}
|
||||
final String propertyName = inferredData.getPropertyName();
|
||||
// column.setPropertyHolder( propertyHolder );
|
||||
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setJoins( secondaryTables );
|
||||
// column.setBuildingContext( context );
|
||||
// property name + suffix is an "explicit" column name
|
||||
|
@ -929,37 +892,6 @@ public class AnnotatedColumn {
|
|||
return columns;
|
||||
}
|
||||
|
||||
public static void checkPropertyConsistency(List<AnnotatedColumn> columns, String propertyName) {
|
||||
if ( columns.size() > 1 ) {
|
||||
for ( int currentIndex = 1; currentIndex < columns.size(); currentIndex++ ) {
|
||||
final AnnotatedColumn current = columns.get( currentIndex );
|
||||
final AnnotatedColumn previous = columns.get( currentIndex - 1 );
|
||||
if ( !current.isFormula() && !previous.isFormula() ) {
|
||||
if ( current.isNullable() != previous.isNullable() ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix nullable with 'not null'"
|
||||
);
|
||||
}
|
||||
if ( current.isInsertable() != previous.isInsertable() ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix insertable with 'insertable=false'"
|
||||
);
|
||||
}
|
||||
if ( current.isUpdatable() != previous.isUpdatable() ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix updatable with 'updatable=false'"
|
||||
);
|
||||
}
|
||||
if ( !current.getExplicitTableName().equals( previous.getExplicitTableName() ) ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix distinct secondary tables"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addIndex(Index index, boolean inSecondPass) {
|
||||
if ( index != null ) {
|
||||
addIndex( index.name(), inSecondPass );
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.hibernate.cfg;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.mapping.Join;
|
||||
import org.hibernate.mapping.Table;
|
||||
|
@ -32,6 +31,7 @@ public class AnnotatedColumns {
|
|||
private final List<AnnotatedColumn> columns = new ArrayList<>();
|
||||
private Table table;
|
||||
private PropertyHolder propertyHolder;
|
||||
private String propertyName; // this is really a .-separated property path
|
||||
private Map<String, Join> joins = Collections.emptyMap();
|
||||
private MetadataBuildingContext buildingContext;
|
||||
|
||||
|
@ -47,6 +47,17 @@ public class AnnotatedColumns {
|
|||
this.propertyHolder = propertyHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* A property path relative to the {@link #getPropertyHolder() PropertyHolder}.
|
||||
*/
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public void setBuildingContext(MetadataBuildingContext buildingContext) {
|
||||
this.buildingContext = buildingContext;
|
||||
}
|
||||
|
@ -62,6 +73,7 @@ public class AnnotatedColumns {
|
|||
public Join getJoin() {
|
||||
final AnnotatedColumn firstColumn = columns.get(0);
|
||||
final String explicitTableName = firstColumn.getExplicitTableName();
|
||||
//note: checkPropertyConsistency() is responsible for ensuring they all have the same table name
|
||||
Join join = joins.get( explicitTableName );
|
||||
if ( join == null ) {
|
||||
// annotation binding seems to use logical and physical naming somewhat inconsistently...
|
||||
|
@ -77,19 +89,27 @@ public class AnnotatedColumns {
|
|||
+ "' is not declared (use '@SecondaryTable' to declare the secondary table)"
|
||||
);
|
||||
}
|
||||
return join;
|
||||
else {
|
||||
return join;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSecondary() {
|
||||
if ( getPropertyHolder() == null ) {
|
||||
throw new AssertionFailure( "Should not call isSecondary() on column w/o persistent class defined" );
|
||||
}
|
||||
final AnnotatedColumn firstColumn = columns.get(0);
|
||||
final String explicitTableName = firstColumn.getExplicitTableName();
|
||||
//note: checkPropertyConsistency() is responsible for ensuring they all have the same table name
|
||||
return isNotEmpty( explicitTableName )
|
||||
&& !getPropertyHolder().getTable().getName().equals( explicitTableName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the table to which these columns belong, taking into account secondary tables.
|
||||
*
|
||||
* @return the {@link Table} given in the code by {@link jakarta.persistence.Column#table()}
|
||||
* and held here by {@code explicitTableName}.
|
||||
* @throws AnnotationException if the table named by {@code explicitTableName} is not found
|
||||
* among the secondary tables in {@code joins}.
|
||||
*/
|
||||
public Table getTable() {
|
||||
if ( table != null ) {
|
||||
return table;
|
||||
|
@ -98,8 +118,7 @@ public class AnnotatedColumns {
|
|||
// all the columns have to be mapped to the same table
|
||||
// even though at the annotation level it looks like
|
||||
// they could each specify a different table
|
||||
final AnnotatedColumn firstColumn = columns.get(0);
|
||||
return firstColumn.isSecondary() ? getJoin().getTable() : getPropertyHolder().getTable();
|
||||
return isSecondary() ? getJoin().getTable() : getPropertyHolder().getTable();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,4 +134,35 @@ public class AnnotatedColumns {
|
|||
public void addColumn(AnnotatedColumn child) {
|
||||
columns.add( child );
|
||||
}
|
||||
|
||||
public void checkPropertyConsistency() {
|
||||
if ( columns.size() > 1 ) {
|
||||
for ( int currentIndex = 1; currentIndex < columns.size(); currentIndex++ ) {
|
||||
final AnnotatedColumn current = columns.get( currentIndex );
|
||||
final AnnotatedColumn previous = columns.get( currentIndex - 1 );
|
||||
if ( !current.isFormula() && !previous.isFormula() ) {
|
||||
if ( current.isNullable() != previous.isNullable() ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix nullable with 'not null'"
|
||||
);
|
||||
}
|
||||
if ( current.isInsertable() != previous.isInsertable() ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix insertable with 'insertable=false'"
|
||||
);
|
||||
}
|
||||
if ( current.isUpdatable() != previous.isUpdatable() ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix updatable with 'updatable=false'"
|
||||
);
|
||||
}
|
||||
if ( !current.getExplicitTableName().equals( previous.getExplicitTableName() ) ) {
|
||||
throw new AnnotationException(
|
||||
"Column mappings for property '" + propertyName + "' mix distinct secondary tables"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,15 +95,13 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
|
||||
public static AnnotatedJoinColumn buildJoinFormula(
|
||||
JoinFormula joinFormula,
|
||||
AnnotatedJoinColumns parent,
|
||||
PropertyHolder propertyHolder,
|
||||
String propertyName) {
|
||||
AnnotatedJoinColumns parent) {
|
||||
final AnnotatedJoinColumn formulaColumn = new AnnotatedJoinColumn();
|
||||
formulaColumn.setFormula( joinFormula.value() );
|
||||
formulaColumn.setReferencedColumn( joinFormula.referencedColumnName() );
|
||||
// formulaColumn.setContext( buildingContext );
|
||||
// formulaColumn.setPropertyHolder( propertyHolder );
|
||||
formulaColumn.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// formulaColumn.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// formulaColumn.setJoins( joins );
|
||||
formulaColumn.setParent( parent );
|
||||
formulaColumn.bind();
|
||||
|
@ -125,10 +123,10 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
+ "' is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'"
|
||||
);
|
||||
}
|
||||
return explicitJoinColumn( joinColumn, comment, parent, propertyHolder, propertyName, defaultColumnSuffix );
|
||||
return explicitJoinColumn( joinColumn, comment, parent, propertyName, defaultColumnSuffix );
|
||||
}
|
||||
else {
|
||||
return implicitJoinColumn( parent, propertyHolder, propertyName, defaultColumnSuffix );
|
||||
return implicitJoinColumn( parent, propertyName, defaultColumnSuffix );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +134,6 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
JoinColumn joinColumn,
|
||||
Comment comment,
|
||||
AnnotatedJoinColumns parent,
|
||||
PropertyHolder propertyHolder,
|
||||
String propertyName,
|
||||
String defaultColumnSuffix) {
|
||||
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
|
||||
|
@ -147,7 +144,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
if ( isEmpty( column.getLogicalColumnName() ) && isNotEmpty( defaultColumnSuffix ) ) {
|
||||
column.setLogicalColumnName( propertyName + defaultColumnSuffix );
|
||||
}
|
||||
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
column.setImplicit( false );
|
||||
column.setParent( parent );
|
||||
column.applyJoinAnnotation( joinColumn, null );
|
||||
|
@ -157,14 +154,13 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
|
||||
private static AnnotatedJoinColumn implicitJoinColumn(
|
||||
AnnotatedJoinColumns parent,
|
||||
PropertyHolder propertyHolder,
|
||||
String propertyName,
|
||||
String defaultColumnSuffix) {
|
||||
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
|
||||
// column.setContext( context );
|
||||
// column.setJoins( joins );
|
||||
// column.setPropertyHolder( propertyHolder );
|
||||
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// property name + suffix is an "explicit" column name
|
||||
if ( isNotEmpty( defaultColumnSuffix ) ) {
|
||||
column.setLogicalColumnName( propertyName + defaultColumnSuffix );
|
||||
|
@ -370,7 +366,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
final String unquotedRefColumn = unquote( referencedColumn );
|
||||
final String collectionColName = isNotEmpty( unquotedLogColName )
|
||||
? unquotedLogColName
|
||||
: getPropertyName() + '_' + unquotedRefColumn;
|
||||
: getParent().getPropertyName() + '_' + unquotedRefColumn;
|
||||
final InFlightMetadataCollector collector = getBuildingContext().getMetadataCollector();
|
||||
final String logicalCollectionColumnName = collector.getDatabase()
|
||||
.getJdbcEnvironment()
|
||||
|
@ -490,7 +486,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
column.setImplicit( true );
|
||||
column.setNullable( false ); //I break the spec, but it's for good
|
||||
// column.setPropertyHolder( propertyHolder );
|
||||
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setJoins( secondaryTables );
|
||||
// column.setContext( context );
|
||||
column.setParent( parent );
|
||||
|
@ -506,7 +502,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
|
|||
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
|
||||
column.setImplicit( true );
|
||||
// column.setPropertyHolder( propertyHolder );
|
||||
column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
// column.setJoins( secondaryTables );
|
||||
// column.setContext( context );
|
||||
column.setNullable( false ); //I break the spec, but it's for good
|
||||
|
|
|
@ -78,7 +78,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
|
|||
final JoinFormula formula = columnOrFormula.formula();
|
||||
final JoinColumn column = columnOrFormula.column();
|
||||
if ( !isEmptyOrNullAnnotationValue( formula.value() ) ) {
|
||||
AnnotatedJoinColumn.buildJoinFormula( formula, parent, propertyHolder, propertyName );
|
||||
AnnotatedJoinColumn.buildJoinFormula( formula, parent );
|
||||
}
|
||||
else {
|
||||
AnnotatedJoinColumn.buildJoinColumn( column, mappedBy, parent, propertyHolder, propertyName );
|
||||
|
@ -87,6 +87,21 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
|
|||
return parent;
|
||||
}
|
||||
|
||||
static AnnotatedJoinColumns buildJoinColumnsWithFormula(
|
||||
String propertyName,
|
||||
JoinFormula joinFormula,
|
||||
Map<String, Join> secondaryTables,
|
||||
PropertyHolder propertyHolder,
|
||||
MetadataBuildingContext context) {
|
||||
final AnnotatedJoinColumns joinColumns = new AnnotatedJoinColumns();
|
||||
joinColumns.setBuildingContext( context );
|
||||
joinColumns.setJoins( secondaryTables );
|
||||
joinColumns.setPropertyHolder( propertyHolder );
|
||||
joinColumns.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
AnnotatedJoinColumn.buildJoinFormula( joinFormula, joinColumns );
|
||||
return joinColumns;
|
||||
}
|
||||
|
||||
public static AnnotatedJoinColumns buildJoinColumns(
|
||||
JoinColumn[] joinColumns,
|
||||
Comment comment,
|
||||
|
|
|
@ -1640,14 +1640,14 @@ public final class AnnotationBinder {
|
|||
final NaturalId naturalIdAnn = property.getAnnotation( NaturalId.class );
|
||||
if ( naturalIdAnn != null ) {
|
||||
if ( joinColumns != null ) {
|
||||
String keyName = "UK_" + Constraint.hashedName( joinColumns.getTable().getName() + "_NaturalID" );
|
||||
for ( AnnotatedColumn column : joinColumns.getColumns() ) {
|
||||
String keyName = "UK_" + Constraint.hashedName( column.getTable().getName() + "_NaturalID" );
|
||||
column.addUniqueKey( keyName, inSecondPass );
|
||||
}
|
||||
}
|
||||
else {
|
||||
String keyName = "UK_" + Constraint.hashedName( columns.getTable().getName() + "_NaturalID" );
|
||||
for ( AnnotatedColumn column : columns.getColumns() ) {
|
||||
String keyName = "UK_" + Constraint.hashedName( column.getTable().getName() + "_NaturalID" );
|
||||
column.addUniqueKey( keyName, inSecondPass );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1111,8 +1111,7 @@ public class BinderHelper {
|
|||
final BasicValue keyDescriptor = keyValueBinder.make();
|
||||
value.setKey( keyDescriptor );
|
||||
keyValueBinder.fillSimpleValue();
|
||||
final String path = qualify( propertyHolder.getEntityName(), inferredData.getPropertyName() );
|
||||
AnnotatedColumn.checkPropertyConsistency( keyColumns.getColumns(), path );
|
||||
keyColumns.checkPropertyConsistency();
|
||||
columns.get(0).linkWithValue( keyDescriptor ); //TODO: nasty
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.cfg;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
|
@ -34,7 +35,6 @@ import static org.hibernate.cfg.AnnotatedColumn.buildFormulaFromAnnotation;
|
|||
import static org.hibernate.cfg.BinderHelper.getOverridableAnnotation;
|
||||
import static org.hibernate.cfg.BinderHelper.getPath;
|
||||
import static org.hibernate.cfg.BinderHelper.getPropertyOverriddenByMapperOrMapsId;
|
||||
import static org.hibernate.cfg.BinderHelper.getRelativePath;
|
||||
import static org.hibernate.internal.util.StringHelper.isEmpty;
|
||||
|
||||
/**
|
||||
|
@ -202,7 +202,6 @@ class ColumnsBuilder {
|
|||
|
||||
private AnnotatedJoinColumns buildExplicitJoinColumns(XProperty property, PropertyData inferredData) {
|
||||
// process @JoinColumns before @Columns to handle collection of entities properly
|
||||
|
||||
final String propertyName = inferredData.getPropertyName();
|
||||
|
||||
final JoinColumn[] joinColumnAnnotations = getJoinColumnAnnotations( property, inferredData );
|
||||
|
@ -232,22 +231,18 @@ class ColumnsBuilder {
|
|||
|
||||
if ( property.isAnnotationPresent( JoinFormula.class) ) {
|
||||
final JoinFormula joinFormula = getOverridableAnnotation( property, JoinFormula.class, buildingContext );
|
||||
return buildJoinColumnsWithFormula( propertyName, joinFormula );
|
||||
return AnnotatedJoinColumns.buildJoinColumnsWithFormula(
|
||||
propertyName,
|
||||
joinFormula,
|
||||
entityBinder.getSecondaryTables(),
|
||||
propertyHolder,
|
||||
buildingContext
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private AnnotatedJoinColumns buildJoinColumnsWithFormula(String propertyName, JoinFormula joinFormula) {
|
||||
final AnnotatedJoinColumns joinColumns = new AnnotatedJoinColumns();
|
||||
joinColumns.setBuildingContext( buildingContext );
|
||||
joinColumns.setJoins( entityBinder.getSecondaryTables() );
|
||||
joinColumns.setPropertyHolder( propertyHolder );
|
||||
joinColumns.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
|
||||
AnnotatedJoinColumn.buildJoinFormula( joinFormula, joinColumns, propertyHolder, propertyName );
|
||||
return joinColumns;
|
||||
}
|
||||
|
||||
private JoinColumnOrFormula[] joinColumnOrFormulaAnnotations(XProperty property, PropertyData inferredData) {
|
||||
if ( property.isAnnotationPresent( JoinColumnOrFormula.class ) ) {
|
||||
return new JoinColumnOrFormula[] { property.getAnnotation( JoinColumnOrFormula.class ) };
|
||||
|
|
|
@ -64,16 +64,13 @@ public class IndexOrUniqueKeySecondPass implements SecondPass {
|
|||
}
|
||||
}
|
||||
if ( column != null ) {
|
||||
table = column.getTable();
|
||||
|
||||
final PropertyHolder propertyHolder = column.getPropertyHolder();
|
||||
final String entityName = ( propertyHolder.isComponent() ) ?
|
||||
propertyHolder.getPersistentClass().getEntityName() :
|
||||
propertyHolder.getEntityName();
|
||||
|
||||
table = column.getParent().getTable();
|
||||
final PropertyHolder propertyHolder = column.getParent().getPropertyHolder();
|
||||
final String entityName = propertyHolder.isComponent()
|
||||
? propertyHolder.getPersistentClass().getEntityName()
|
||||
: propertyHolder.getEntityName();
|
||||
final PersistentClass persistentClass = persistentClasses.get( entityName );
|
||||
final Property property = persistentClass.getProperty( column.getPropertyName() );
|
||||
|
||||
final Property property = persistentClass.getProperty( column.getParent().getPropertyName() );
|
||||
if ( property.getValue() instanceof Component ) {
|
||||
final Component component = (Component) property.getValue();
|
||||
final List<Column> columns = new ArrayList<>();
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.hibernate.mapping.ToOne;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hibernate.cfg.AnnotatedColumn.checkPropertyConsistency;
|
||||
import static org.hibernate.cfg.AnnotationBinder.matchIgnoreNotFoundWithFetchType;
|
||||
import static org.hibernate.cfg.BinderHelper.getCascadeStrategy;
|
||||
import static org.hibernate.cfg.BinderHelper.getFetchMode;
|
||||
|
@ -196,7 +195,6 @@ public class ToOneBinder {
|
|||
cascadeStrategy,
|
||||
joinColumns,
|
||||
optional,
|
||||
propertyHolder,
|
||||
inferredData,
|
||||
isIdentifierMapper,
|
||||
propertyBinder,
|
||||
|
@ -242,7 +240,6 @@ public class ToOneBinder {
|
|||
String cascadeStrategy,
|
||||
AnnotatedJoinColumns columns,
|
||||
boolean optional,
|
||||
PropertyHolder propertyHolder,
|
||||
PropertyData inferredData,
|
||||
boolean isIdentifierMapper,
|
||||
PropertyBinder propertyBinder,
|
||||
|
@ -250,7 +247,7 @@ public class ToOneBinder {
|
|||
boolean hasSpecjManyToOne,
|
||||
String propertyName) {
|
||||
|
||||
checkPropertyConsistency( columns.getColumns(), qualify( propertyHolder.getEntityName(), propertyName ) );
|
||||
columns.checkPropertyConsistency();
|
||||
|
||||
//PropertyBinder binder = new PropertyBinder();
|
||||
propertyBinder.setName( propertyName );
|
||||
|
|
|
@ -1069,16 +1069,12 @@ public class BasicValueBinder implements JdbcTypeIndicators {
|
|||
this.explicitBasicTypeName = explicitType;
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
AnnotatedColumn.checkPropertyConsistency( columns.getColumns(), propertyName );
|
||||
}
|
||||
|
||||
public BasicValue make() {
|
||||
if ( basicValue != null ) {
|
||||
return basicValue;
|
||||
}
|
||||
|
||||
validate();
|
||||
columns.checkPropertyConsistency();
|
||||
|
||||
LOG.debugf( "building BasicValue for %s", propertyName );
|
||||
|
||||
|
@ -1130,7 +1126,7 @@ public class BasicValueBinder implements JdbcTypeIndicators {
|
|||
final AnnotatedJoinColumns joinColumns = new AnnotatedJoinColumns();
|
||||
joinColumns.setBuildingContext( buildingContext );
|
||||
joinColumns.setPropertyHolder( columns.getPropertyHolder() );
|
||||
joinColumns.setPropertyName( firstColumn.getPropertyName() );
|
||||
joinColumns.setPropertyName( columns.getPropertyName() );
|
||||
//TODO: resetting the parent here looks like a dangerous thing to do
|
||||
// should we be cloning them first (the legacy code did not)
|
||||
for ( AnnotatedColumn column : columns.getColumns() ) {
|
||||
|
|
|
@ -154,7 +154,6 @@ import static org.hibernate.cfg.AnnotatedColumn.buildColumnFromAnnotation;
|
|||
import static org.hibernate.cfg.AnnotatedColumn.buildColumnFromNoAnnotation;
|
||||
import static org.hibernate.cfg.AnnotatedColumn.buildColumnsFromAnnotations;
|
||||
import static org.hibernate.cfg.AnnotatedColumn.buildFormulaFromAnnotation;
|
||||
import static org.hibernate.cfg.AnnotatedColumn.checkPropertyConsistency;
|
||||
import static org.hibernate.cfg.AnnotatedJoinColumns.buildJoinColumnsWithDefaultColumnSuffix;
|
||||
import static org.hibernate.cfg.AnnotatedJoinColumns.buildJoinTableJoinColumns;
|
||||
import static org.hibernate.cfg.AnnotationBinder.fillComponent;
|
||||
|
@ -417,11 +416,9 @@ public abstract class CollectionBinder {
|
|||
final String mappedBy;
|
||||
final ReflectionManager reflectionManager = context.getBootstrapContext().getReflectionManager();
|
||||
if ( oneToManyAnn != null ) {
|
||||
for ( AnnotatedJoinColumn column : joinColumns.getJoinColumns() ) {
|
||||
if ( column.isSecondary() ) {
|
||||
//TODO: fix the error message
|
||||
throw new NotYetImplementedException( "Collections having FK in secondary table" );
|
||||
}
|
||||
if ( joinColumns.isSecondary() ) {
|
||||
//TODO: fix the error message
|
||||
throw new NotYetImplementedException( "Collections having FK in secondary table" );
|
||||
}
|
||||
collectionBinder.setFkJoinColumns( joinColumns );
|
||||
mappedBy = oneToManyAnn.mappedBy();
|
||||
|
@ -433,11 +430,9 @@ public abstract class CollectionBinder {
|
|||
collectionBinder.setOneToMany( true );
|
||||
}
|
||||
else if ( elementCollectionAnn != null ) {
|
||||
for ( AnnotatedJoinColumn column : joinColumns.getJoinColumns() ) {
|
||||
if ( column.isSecondary() ) {
|
||||
//TODO: fix the error message
|
||||
throw new NotYetImplementedException( "Collections having FK in secondary table" );
|
||||
}
|
||||
if ( joinColumns.isSecondary() ) {
|
||||
//TODO: fix the error message
|
||||
throw new NotYetImplementedException( "Collections having FK in secondary table" );
|
||||
}
|
||||
collectionBinder.setFkJoinColumns( joinColumns );
|
||||
mappedBy = "";
|
||||
|
@ -1852,8 +1847,8 @@ public abstract class CollectionBinder {
|
|||
|
||||
final DependantValue key = new DependantValue( buildingContext, collection.getCollectionTable(), keyValue );
|
||||
key.setTypeName( null );
|
||||
joinColumns.checkPropertyConsistency();
|
||||
final List<AnnotatedColumn> columns = joinColumns.getColumns();
|
||||
checkPropertyConsistency( columns, collection.getOwnerEntityName() );
|
||||
key.setNullable( columns.isEmpty() || columns.get(0).isNullable() );
|
||||
key.setUpdateable( columns.isEmpty() || columns.get(0).isUpdatable() );
|
||||
key.setCascadeDeleteEnabled( cascadeDeleteEnabled );
|
||||
|
|
Loading…
Reference in New Issue