Hibernate ORM IdentityGenerator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM IdentityGenerator class.

This code example shows how to use the following methods:
 * This IdentityGenerator allows a programmer to override the "generated" id, with an "assigned" id 
 * at runtime by simply setting the primary key property. 
 *  
 * @author paul.shemansky@gmail.com 
 */ 
public class NativeIfNotAssignedIdentityGenerator extends IdentityGenerator implements Configurable {
	 
	private String entityName;
	 
	@Override 
	public Serializable generate(SessionImplementor session, Object entity) throws HibernateException {
		Serializable id;
		EntityPersister persister = session.getEntityPersister(entityName, entity);
		// Determine if an ID has been assigned. 
		id = persister.getIdentifier(entity, session);
		if (id == null) {
			id = super.generate(session, entity);
		} 
		return id;
	} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
/** 
 * Simple {@link IdentityGenerator} implementation for testing composite-id. 
 *  
 * @author Jacob Robertson 
 */ 
public class PurchaseRecordIdGenerator extends IdentityGenerator {
 
	private static int nextPurchaseNumber = 2;
	private static int nextPurchaseSequence = 3;
	 
	public Serializable generate(SessionImplementor s, Object obj) {
		return new PurchaseRecord.Id( 
				nextPurchaseNumber++, 
				String.valueOf(nextPurchaseSequence++));
	} 
	 
} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
 *  
 * 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 
        } 
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java