All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.id.Assigned Maven / Gradle / Ivy

The newest version!
/*
 * 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 beforeQuery 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