// This is a @OneToOne mapped to a physical o.h.mapping.ManyToOne
if ( unique ) {
value.markAsLogicalOneToOne();
}
value.setReferencedEntityName( ToOneBinder.getReferenceEntityName( inferredData, targetEntity, mappings ) );
final XProperty property = inferredData.getProperty();
defineFetchingStrategy( value, property );
//value.setFetchMode( fetchMode );
value.setIgnoreNotFound( ignoreNotFound );
value.setCascadeDeleteEnabled( cascadeOnDelete );
//value.setLazy( fetchMode != FetchMode.JOIN );
if ( !optional ) {
for ( Ejb3JoinColumn column : columns ) {
column.setNullable( false );
}
}
if ( property.isAnnotationPresent( MapsId.class ) ) {
//read only
for ( Ejb3JoinColumn column : columns ) {
column.setInsertable( false );
column.setUpdatable( false );
}
}
final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
//Make sure that JPA1 key-many-to-one columns are read only tooj
boolean hasSpecjManyToOne=false;
if ( mappings.isSpecjProprietarySyntaxEnabled() ) {
String columnName = "";
for ( XProperty prop : inferredData.getDeclaringClass()
.getDeclaredProperties( AccessType.FIELD.getType() ) ) {
if ( prop.isAnnotationPresent( Id.class ) && prop.isAnnotationPresent( Column.class ) ) {
columnName = prop.getAnnotation( Column.class ).name();
}
if ( property.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
&& ! BinderHelper.isEmptyAnnotationValue( joinColumn.name() )
&& joinColumn.name().equals( columnName )
&& !property.isAnnotationPresent( MapsId.class ) ) {
hasSpecjManyToOne = true;
for ( Ejb3JoinColumn column : columns ) {
column.setInsertable( false );
column.setUpdatable( false );
}
}
}
}
value.setTypeName( inferredData.getClassOrElementName() );
final String propertyName = inferredData.getPropertyName();
value.setTypeUsingReflection( propertyHolder.getClassName(), propertyName );
String fkName = null;
if ( joinColumn != null && joinColumn.foreignKey() != null ) {
fkName = joinColumn.foreignKey().name();
}
if ( StringHelper.isEmpty( fkName ) ) {
ForeignKey fk = property.getAnnotation( ForeignKey.class );
fkName = fk != null ? fk.name() : "";
}
if ( !StringHelper.isEmpty( fkName ) ) {
value.setForeignKeyName( fkName );
}