net.croz.nrich.search.util.AttributeResolvingUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nrich-search Show documentation
Show all versions of nrich-search Show documentation
Provides an easy way of querying of JPA entities through automatic query creation from passed in data (either strings or classes that hold restriction values)
The newest version!
package net.croz.nrich.search.util;
import jakarta.persistence.metamodel.Attribute;
import jakarta.persistence.metamodel.ManagedType;
import org.hibernate.metamodel.model.domain.AbstractManagedType;
public final class AttributeResolvingUtil {
private AttributeResolvingUtil() {
}
public static Attribute, ?> resolveAttributeByName(ManagedType> managedType, String attributeName) {
if (managedType instanceof AbstractManagedType> abstractManagedType) {
Attribute, ?> attribute = abstractManagedType.findAttribute(attributeName);
if (attribute == null) {
return abstractManagedType.findSubTypesAttribute(attributeName);
}
return attribute;
}
else {
try {
return managedType.getAttribute(attributeName);
}
catch (Exception ignored) {
return null;
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy