1 package org.hibernate.id; 3 4 import java.io.Serializable ; 5 import java.util.Properties ; 6 7 import org.hibernate.HibernateException; 8 import org.hibernate.MappingException; 9 import org.hibernate.dialect.Dialect; 10 import org.hibernate.engine.SessionImplementor; 11 import org.hibernate.type.Type; 12 13 21 22 public class Assigned implements IdentifierGenerator, Configurable { 23 24 private String entityName; 25 26 public Serializable generate(SessionImplementor session, Object obj) throws HibernateException { 27 28 final Serializable id = session.getEntityPersister( entityName, obj ) 29 .getIdentifier( obj, session.getEntityMode() ); 31 32 if (id==null) { 33 throw new IdentifierGenerationException( 34 "ids for this class must be manually assigned before calling save(): " + 35 entityName 36 ); 37 } 38 39 return id; 40 } 41 42 public void configure(Type type, Properties params, Dialect d) 43 throws MappingException { 44 entityName = params.getProperty(ENTITY_NAME); 45 if (entityName==null) { 46 throw new MappingException("no entity name"); 47 } 48 } 49 } 50 51 52 53 54 55 56 | Popular Tags |