Java Code Examples for org.hibernate.mapping.OneToOne#setFetchMode()
The following examples show how to use
org.hibernate.mapping.OneToOne#setFetchMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrailsDomainBinder.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne, String path, String sessionFactoryBeanName) { PropertyConfig config = getPropertyConfig(property); final Association otherSide = property.getInverseSide(); final boolean hasOne = isHasOne(otherSide); oneToOne.setConstrained(hasOne); oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FROM_PARENT : ForeignKeyDirection.TO_PARENT); oneToOne.setAlternateUniqueKey(true); if (config != null && config.getFetchMode() != null) { oneToOne.setFetchMode(config.getFetchMode()); } else { oneToOne.setFetchMode(FetchMode.DEFAULT); } oneToOne.setReferencedEntityName(otherSide.getOwner().getName()); oneToOne.setPropertyName(property.getName()); oneToOne.setReferenceToPrimaryKey(false); bindOneToOneInternal(property, oneToOne, path); if (hasOne) { PropertyConfig pc = getPropertyConfig(property); bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName); } else { oneToOne.setReferencedPropertyName(otherSide.getName()); } }
Example 2
Source File: ModelBinder.java From lams with GNU General Public License v2.0 | 4 votes |
public void bindOneToOne( final MappingDocument sourceDocument, final SingularAttributeSourceOneToOne oneToOneSource, final OneToOne oneToOneBinding) { oneToOneBinding.setPropertyName( oneToOneSource.getName() ); relationalObjectBinder.bindFormulas( sourceDocument, oneToOneSource.getFormulaSources(), oneToOneBinding ); if ( oneToOneSource.isConstrained() ) { if ( oneToOneSource.getCascadeStyleName() != null && oneToOneSource.getCascadeStyleName().contains( "delete-orphan" ) ) { throw new MappingException( String.format( Locale.ENGLISH, "one-to-one attribute [%s] cannot specify orphan delete cascading as it is constrained", oneToOneSource.getAttributeRole().getFullPath() ), sourceDocument.getOrigin() ); } oneToOneBinding.setConstrained( true ); oneToOneBinding.setForeignKeyType( ForeignKeyDirection.FROM_PARENT ); } else { oneToOneBinding.setForeignKeyType( ForeignKeyDirection.TO_PARENT ); } oneToOneBinding.setLazy( oneToOneSource.getFetchCharacteristics().getFetchTiming() == FetchTiming.DELAYED ); oneToOneBinding.setFetchMode( oneToOneSource.getFetchCharacteristics().getFetchStyle() == FetchStyle.SELECT ? FetchMode.SELECT : FetchMode.JOIN ); oneToOneBinding.setUnwrapProxy( oneToOneSource.getFetchCharacteristics().isUnwrapProxies() ); if ( StringHelper.isNotEmpty( oneToOneSource.getReferencedEntityAttributeName() ) ) { oneToOneBinding.setReferencedPropertyName( oneToOneSource.getReferencedEntityAttributeName() ); oneToOneBinding.setReferenceToPrimaryKey( false ); } else { oneToOneBinding.setReferenceToPrimaryKey( true ); } // todo : probably need some reflection here if null oneToOneBinding.setReferencedEntityName( oneToOneSource.getReferencedEntityName() ); if ( oneToOneSource.isEmbedXml() == Boolean.TRUE ) { DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfEmbedXmlSupport(); } if ( StringHelper.isNotEmpty( oneToOneSource.getExplicitForeignKeyName() ) ) { oneToOneBinding.setForeignKeyName( oneToOneSource.getExplicitForeignKeyName() ); } oneToOneBinding.setCascadeDeleteEnabled( oneToOneSource.isCascadeDeleteEnabled() ); }