1

Is there a way to get the current node name (or the entire chain) for a Path instance? As far as I can tell, there is no method within Path to do so. I tried the toString() method, but that is not overridden in EclipseLink (it gets you the default output: org.eclipse...PathImpl@331a119a).

I'm using EclipseLink, so a EclipseLink specific solution is fine with me.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102

1 Answers1

0

When I checked the path I wanted to get the name for using the debugger, I noticed the EclipseLink implementation of Path has a field called currentNode of type QueryKeyExpression which has the name I was after. So I wrote a utility method:

public static QueryKeyExpression getCurrentNode(Path<?> path) {
  try {
    return (QueryKeyExpression) ReflectionUtils.getValue(path, "currentNode");
  }
  catch (NoSuchFieldException ex) {
    throw new IllegalStateException(ex);
  }
}

Which allows me to get the name like:

JpaUtils.getCurrentNode(path).getName()

See also:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102