0
 
	/** 
	 * {@inheritDoc} 
	 */ 
	public Serializable generate(SessionImplementor sessionImplementor, Object object) {
		Session session = ( Session ) sessionImplementor;
 
		final EntityPersister persister = sessionImplementor.getFactory().getEntityPersister( entityName );
		Object associatedObject = persister.getPropertyValue( object, propertyName );
		if ( associatedObject == null ) { 
			throw new IdentifierGenerationException(
					"attempted to assign id from null one-to-one property [" + getRole() + "]"
			); 
		} 
 
		final EntityType foreignValueSourceType;
		final Type propertyType = persister.getPropertyType( propertyName );
		if ( propertyType.isEntityType() ) {
			// the normal case 
			foreignValueSourceType = (EntityType) propertyType;
		} 
		else { 
			// try identifier mapper 
			foreignValueSourceType = (EntityType) persister.getPropertyType( "_identifierMapper." + propertyName );
		} 
 
		Serializable id;
		try { 
			id = ForeignKeys.getEntityIdentifierIfNotUnsaved(
					foreignValueSourceType.getAssociatedEntityName(),
					associatedObject, 
					sessionImplementor
			); 
		} 
		catch (TransientObjectException toe) {
			id = session.save( foreignValueSourceType.getAssociatedEntityName(), associatedObject );
		} 
 
		if ( session.contains(object) ) {
			//abort the save (the object is already saved by a circular cascade) 
			return IdentifierGeneratorHelper.SHORT_CIRCUIT_INDICATOR;
			//throw new IdentifierGenerationException("save associated object first, or disable cascade for inverse association"); 
		} 
		return id;
	} 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE