UserSession txLogoutExistingSession(Long userId) throws DuplicateUserEmailDetected {
		Session session = HibernateUtil.getCurrentSession();

		List<?> list = session.createQuery(
				"from UserSession as us where us.user.id = :userId " +
				"and (us.lastActivity+timeout) > :now")
			.setLong("userId", userId)
			.setDate("now", new Date())
			.list();	
		
		// This is a fail-state.
		if( list.size() > 1 ) {
			throw new DuplicateUserEmailDetected();
		}
		
		UserSession foundSession = null ;
		
		// We found a single existing user.
		if( list.size() == 1 ) {
			foundSession = (UserSession) list.get(0);
			
			// Invalidate/logout the foundSession.
			foundSession.setLoggedOut(true);
			session.saveOrUpdate(foundSession);
		}
		
		// We're done.
		return foundSession ;
	}