FileDocCategorySizeDatePackage
NamedQueryLoader.javaAPI DocHibernate 3.2.52019Thu Jun 15 02:50:12 BST 2006org.hibernate.persister.entity

NamedQueryLoader

public final class NamedQueryLoader extends Object implements org.hibernate.loader.entity.UniqueEntityLoader
Not really a Loader, just a wrapper around a named query.
author
Gavin King

Fields Summary
private final String
queryName
private final EntityPersister
persister
private static final Log
log
Constructors Summary
public NamedQueryLoader(String queryName, EntityPersister persister)


	     
		super();
		this.queryName = queryName;
		this.persister = persister;
	
Methods Summary
public java.lang.Objectload(java.io.Serializable id, java.lang.Object optionalObject, org.hibernate.engine.SessionImplementor session)

		
		if ( log.isDebugEnabled() ) {
			log.debug(
					"loading entity: " + persister.getEntityName() + 
					" using named query: " + queryName 
				);
		}
		
		AbstractQueryImpl query = (AbstractQueryImpl) session.getNamedQuery(queryName);
		if ( query.hasNamedParameters() ) {
			query.setParameter( 
					query.getNamedParameters()[0], 
					id, 
					persister.getIdentifierType() 
				);
		}
		else {
			query.setParameter( 0, id, persister.getIdentifierType() );
		}
		query.setOptionalId(id);
		query.setOptionalEntityName( persister.getEntityName() );
		query.setOptionalObject(optionalObject);
		query.setFlushMode( FlushMode.MANUAL );
		query.list();
		
		// now look up the object we are really interested in!
		// (this lets us correctly handle proxies and multi-row
		// or multi-column queries)
		return session.getPersistenceContext()
				.getEntity( new EntityKey( id, persister, session.getEntityMode() ) );