[hibernate-dev] [ORM] Do we have a way to check if an object is an entity?

Guillaume Smet guillaume.smet at gmail.com
Thu Apr 25 13:14:15 EDT 2019


Hi,

In Hibernate Validator, we have a TraversableResolver which avoids to
validate the uninitialized properties of an entity.

This is done in
https://github.com/hibernate/hibernate-validator/blob/master/engine/src/main/java/org/hibernate/validator/internal/engine/resolver/JPATraversableResolver.java#L35
and, as you can see, we execute Persistence.getPersistenceUtil().isLoaded(
traversableObject, traversableProperty.getName() ) even if the
traversableObject has nothing to do with Hibernate ORM.

I'm looking for an API that could tell me if an object is a class
potentially managed by ORM (be it an entity, an embeddable or whatever: any
class potentially containing a lazy field).

I was thinking that maybe injecting an EntityManagerFactory (it would
require CDI though) and using the Metamodel could somehow work... but the
PersistenceUtil API we currently use is capable of dealing with several
persistence providers and I don't think the injected EntityManagerFactory
approach will fly in this case.

Is there something I could use to do that, that would be portable and cover
the cases currently (somehow) taken care of?

Any ideas welcome.

Thanks!

-- 
Guillaume


More information about the hibernate-dev mailing list