I have a javax.persistence.criteria.Path<X> field (obtained by from.get<T>(fieldName) somewhere else in the codebase) and I want to find corresponding class name and field name as strings. Currently I’m doing this:
val parentClassName = field.parentPath.type().javaType.simpleName
val fieldName = field.attribute.name
For that to be possible I need to cast the field to PathImplementor which is Hibernate specific, though. Is there any standard JPA way how to achieve that?
Path has a getParentPath() method through which you can obtain the From. Through that, you can figure out the entity class name. Path#getModel should return you the javax.persistence.metamodel.Attribute, which then exposes an attribute name.