Hibernate3自定义主键生成器 String主键 继承TableGenerator

import java.io.Serializable; import java.util.Properties; import org.hibernate.MappingException; import org.hibernate.dialect.Dialect; import org.hibernate.engine.SessionImplementor; import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.type.IntegerType; import org.hibernate.type.Type; public class IDGenerator extends TableGenerator{ @Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { // 如果这里写成super.configure(type, params, dialect);会造成死循环 // 因为TableGenerator默认Integer类型主键 super.configure(new IntegerType(), params, dialect); } @Override public synchronized Serializable generate(SessionImplementor session, Object obj) { // 主键是前缀+序号 return "小乌龟"+super.generate(session, obj); } }

你可能感兴趣的:(Hibernate)