org.hibernate.id.Assigned Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beangle-hibernate-core Show documentation
Show all versions of beangle-hibernate-core Show documentation
Hibernate Orm Core Shade,Support Scala Collection
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.id;
import java.io.Serializable;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;
/**
* assigned
*
* An IdentifierGenerator that returns the current identifier assigned
* to an instance.
*
* @author Gavin King
*/
public class Assigned implements IdentifierGenerator, Configurable {
private String entityName;
public Serializable generate(SharedSessionContractImplementor session, Object obj) throws HibernateException {
//TODO: cache the persister, this shows up in yourkit
final Serializable id = session.getEntityPersister( entityName, obj ).getIdentifier( obj, session );
if ( id == null ) {
throw new IdentifierGenerationException(
"ids for this class must be manually assigned before calling save(): " + entityName
);
}
return id;
}
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
entityName = params.getProperty( ENTITY_NAME );
if ( entityName == null ) {
throw new MappingException("no entity name");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy