FileDocCategorySizeDatePackage
SelectGenerator.javaAPI DocHibernate 3.2.54676Fri Jan 19 05:55:08 GMT 2007org.hibernate.id

SelectGenerator

public class SelectGenerator extends AbstractPostInsertGenerator implements Configurable
A generator that selects the just inserted row to determine the identifier value assigned by the database. The correct row is located using a unique key.

One mapping parameter is required: key (unless a natural-id is defined in the mapping).

author
Gavin King

Fields Summary
private String
uniqueKeyPropertyName
Constructors Summary
Methods Summary
public voidconfigure(org.hibernate.type.Type type, java.util.Properties params, org.hibernate.dialect.Dialect d)

		uniqueKeyPropertyName = params.getProperty( "key" );
	
private static java.lang.StringdetermineNameOfPropertyToUse(PostInsertIdentityPersister persister, java.lang.String supplied)

		if ( supplied != null ) {
			return supplied;
		}
		int[] naturalIdPropertyIndices = persister.getNaturalIdentifierProperties();
		if ( naturalIdPropertyIndices == null ){
			throw new IdentifierGenerationException(
					"no natural-id property defined; need to specify [key] in " +
					"generator parameters"
			);
		}
		if ( naturalIdPropertyIndices.length > 1 ) {
			throw new IdentifierGenerationException(
					"select generator does not currently support composite " +
					"natural-id properties; need to specify [key] in generator parameters"
			);
		}
		ValueInclusion inclusion = persister.getPropertyInsertGenerationInclusions() [ naturalIdPropertyIndices[0] ];
		if ( inclusion != ValueInclusion.NONE ) {
			throw new IdentifierGenerationException(
					"natural-id also defined as insert-generated; need to specify [key] " +
					"in generator parameters"
			);
		}
		return persister.getPropertyNames() [ naturalIdPropertyIndices[0] ];
	
public org.hibernate.id.insert.InsertGeneratedIdentifierDelegategetInsertGeneratedIdentifierDelegate(PostInsertIdentityPersister persister, org.hibernate.dialect.Dialect dialect, boolean isGetGeneratedKeysEnabled)

		return new SelectGeneratorDelegate( persister, dialect, uniqueKeyPropertyName );