samples/xml/dms/src/main/java/sample/dms/DocumentDaoImpl.java
private Directory getDirectoryWithImmediateParentPopulated(final Long id) {
		return getJdbcTemplate().queryForObject(SELECT_FROM_DIRECTORY_SINGLE,
				new Object[] { id }, new RowMapper<Directory>() {
					public Directory mapRow(ResultSet rs, int rowNumber)
							throws SQLException {
						Long parentDirectoryId = new Long(rs
								.getLong("parent_directory_id"));
						Directory parentDirectory = Directory.ROOT_DIRECTORY;
						if (parentDirectoryId != null
								&& !parentDirectoryId.equals(new Long(-1))) {
							// Need to go and lookup the parent, so do that first
							parentDirectory = getDirectoryWithImmediateParentPopulated(parentDirectoryId);
						}
						Directory directory = new Directory(rs
								.getString("directory_name"), parentDirectory);
						FieldUtils.setProtectedFieldValue("id", directory,
								new Long(rs.getLong("id")));
						return directory;
					}
				});
	}
private Directory getDirectoryWithImmediateParentPopulated(final Long id) {
		return getJdbcTemplate().queryForObject(SELECT_FROM_DIRECTORY_SINGLE,
				new Object[] { id }, new RowMapper<Directory>() {
					public Directory mapRow(ResultSet rs, int rowNumber)
							throws SQLException {
						Long parentDirectoryId = new Long(rs
								.getLong("parent_directory_id"));
						Directory parentDirectory = Directory.ROOT_DIRECTORY;
						if (parentDirectoryId != null
								&& !parentDirectoryId.equals(new Long(-1))) {
							// Need to go and lookup the parent, so do that first
							parentDirectory = getDirectoryWithImmediateParentPopulated(parentDirectoryId);
						}
						Directory directory = new Directory(rs
								.getString("directory_name"), parentDirectory);
						FieldUtils.setProtectedFieldValue("id", directory,
								new Long(rs.getLong("id")));
						return directory;
					}
				});
	}
Executes recursive SQL as needed to build a full Directory hierarchy of objects