hibernate的映射實現得真複雜spring
在Loader中有一個getRow就是完成結果映射的session
private Object[] getRow( final ResultSet rs, final Loadable[] persisters, final EntityKey[] keys, final Object optionalObject, final EntityKey optionalObjectKey, final LockMode[] lockModes, final List hydratedObjects, final SharedSessionContractImplementor session) throws HibernateException, SQLException { final int cols = persisters.length; final EntityAliases[] descriptors = getEntityAliases(); if ( LOG.isDebugEnabled() ) { LOG.debugf( "Result row: %s", StringHelper.toString( keys ) ); } final Object[] rowResults = new Object[cols]; for ( int i = 0; i < cols; i++ ) { Object object = null; EntityKey key = keys[i]; if ( keys[i] == null ) { //do nothing } else { //If the object is already loaded, return the loaded one object = session.getEntityUsingInterceptor( key ); if ( object != null ) { //its already loaded so don't need to hydrate it instanceAlreadyLoaded( rs, i, persisters[i], key, object, lockModes[i], session ); } else { object = instanceNotYetLoaded( rs, i, persisters[i], descriptors[i].getRowIdAlias(), key, lockModes[i], optionalObjectKey, optionalObject, hydratedObjects, session ); } } rowResults[i] = object; } return rowResults; }
真是複雜,spring-jdbc還簡單一點,不知道爲啥hibernate