public void insert()

in core/src/main/java/org/hibernate/ogm/persister/impl/OgmEntityPersister.java [1410:1478]


	public void insert(Serializable id, Object[] fields, Object object, SharedSessionContractImplementor session)
			throws HibernateException {

		// TODO: Atm. the table span is always 1, i.e. mappings to several tables (@SecondaryTable) are not supported
		final int span = getTableSpan();

		//insert operations are always dynamic in OGM
		boolean[] propertiesToInsert = getPropertiesToInsert( fields );
		for ( int j = 0; j < span; j++ ) {
			if ( isInverseTable( j ) ) {
				return;
			}

			//note: it is conceptually possible that a UserType could map null to
			//	  a non-null value, so the following is arguable:
			if ( isNullableTable( j ) && isAllNull( fields, j ) ) {
				return;
			}

			if ( log.isTraceEnabled() ) {
				log.trace( "Inserting entity: " + MessageHelper.infoString( this, id, getFactory() ) );
				if ( j == 0 && isVersioned() ) {
					log.trace( "Version: " + Versioning.getVersion( fields, this ) );
				}
			}

			final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );

			Tuple resultset = null;

			if ( duplicateInsertPreventionStrategy == DuplicateInsertPreventionStrategy.LOOK_UP ) {
				resultset = getFreshTuple( key, session );

				if ( j == 0 && resultset != null ) {
					if ( invocationCollectingGridDialect == null ) {
						throw log.mustNotInsertSameEntityTwice( MessageHelper.infoString( this, id, getFactory() ), null );
					}
					else {
						try {
							invocationCollectingGridDialect.onInsertOrUpdateTupleFailure( key, resultset, new TupleAlreadyExistsException( key ) );
						}
						catch ( TupleAlreadyExistsException taee ) {
							throw log.mustNotInsertSameEntityTwice( MessageHelper.infoString( this, id, getFactory() ), taee );
						}
					}
				}
			}

			resultset = createNewResultSetIfNull( key, resultset, id, session );
			resultset.setSnapshotType( SnapshotType.INSERT );
			TuplePointer tuplePointer = saveSharedTuple( object, resultset, session );

			// add the discriminator
			if ( j == 0 && discriminator.isNeeded() ) {
				resultset.put( getDiscriminatorColumnName(), getDiscriminatorValue() );
			}

			dehydrate( resultset, fields, propertiesToInsert, j, id, session );

			try {
				insertOrUpdateTuple( key, tuplePointer, hasInsertGeneratedProperties(), session );
			}
			catch ( TupleAlreadyExistsException taee ) {
				throw log.mustNotInsertSameEntityTwice( MessageHelper.infoString( this, id, getFactory() ), taee );
			}

			addToInverseAssociations( resultset, 0, id, session );
		}
	}