Code example for IdentityGenerator

0
 *  
 * Mapping parameters supported: none 
 *  
 * @author wallacew 
 */ 
public class IDPresentAwareGenerator extends IdentityGenerator {
 
    @Override 
    public Serializable generate(SessionImplementor session, Object obj) {
        Serializable result = null;
 
        // if user has set the id manually, don't change it. 
        try { 
            Class<?> clazz = obj.getClass();
            Method idMethod = clazz.getMethod("getId");
            result = (Serializable) idMethod.invoke(obj);
        } 
        catch (Exception e) {
            // do nothing 
        } 
Experience pair programming with AI  Get Codota for Java