OpenJPA criteriaBuilder nested object property fetch

For any arbitrary nested attribute path ("relation.subRelation.attribute"):

private Path<T> getPath(Root<T> root, String attributeName) {
    Path<T> path = root;
    for (String part : attributeName.split("\\.")) {
        path = path.get(part);
    }
    return path;
}

Heh, the solution is suprisingly simple - and it looks really ugly, but it works.

predicate1 = criteriaBuilder.and(predicate1, criteriaBuilder.equal(rootObj.get("Y").<String> get("Z"), param1));}

I really don't know if there is a more elegant solution to this.