[quote="jitendra_agrawal"]Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
public class GeneratedIdentifierGenerator implements IdentifierGenerator, Configurable
{
public GeneratedIdentifierGenerator()
{
super();
}
/**
* The delegate parameter specifies the underlying ID generator to use.
*/
public static final String DELEGATE = "delegate";
private IdentifierGenerator assignedGenerator;
private IdentifierGenerator delegateGenerator;
public Serializable generate(SessionImplementor session, Object object) throws HibernateException, SQLException {
AbstractDomainObject abstractDomainObject = (AbstractDomainObject) object;
if (abstractDomainObject.getId() != null) {
return assignedGenerator.generate(session, object);
} else {
return delegateGenerator.generate(session, object);
}
}
public void configure(Type type, Properties params, Dialect d) throws MappingException {
String generatorName = params.getProperty(DELEGATE);
if (generatorName == null) throw new MappingException("param named "delegate" is required for object generation strategy");
// Create the delegate and assigned ID generators
delegateGenerator = IdentifierGeneratorFactory.create(generatorName, type, params, d);
assignedGenerator = IdentifierGeneratorFactory.create("assigned", type, params, d);
}
}