[hibernate-dev] [ORM] Do we have a way to check if an object is an entity?
Steve Ebersole
steve at hibernate.org
Thu Apr 25 14:42:39 EDT 2019
That's going to depend on which "bootstrap" they use. JPA defines 2 which
it terms "SE" and "EE". Not sure this will work in all EE bootstrap
environments, but you have:
````
PersistenceProviderResolver resolver =
PersistenceProviderResolverHolder.getPersistenceProviderResolver();
List<PersistenceProvider> providers = resolver.getPersistenceProviders();
````
On Thu, Apr 25, 2019 at 1:25 PM Guillaume Smet <guillaume.smet at gmail.com>
wrote:
> On Thu, Apr 25, 2019 at 8:05 PM Steve Ebersole <steve at hibernate.org>
> wrote:
>
>> EMF + Metamodel are standard JPA contracts:
>>
>> ````
>> try {
>> emf.getMetamodel().managedType( theClass );
>> }
>> catch ( IllegalArgumentException e ) {
>> // JPA defined exception if the passed class is not a managed type
>> }
>>
>> Again, that will (should) work on any provider
>>
>
> Thanks.
>
> So I was pretty sure it would work with any provider. My question was
> more: how to make it work with multiple providers? Right now, the current
> implementation is very low level and doesn't use anything but JPA to get
> the EMF. But I didn't see any way to get all the potentially created EMF.
>
> I suppose I could try to get all the EMF from CDI - that would make this
> feature CDI-compatible only but I suppose it's acceptable. I will probably
> will need to do that after everything is initialized or I will have a
> chicken and egg problem as the EMF needs to get the ValidatorFactory. The
> thing is that, in this case, all the EMF should be created via CDI or it
> won't work very well.
>
> Collecting once and for all all the managed types via
> emf.getMetamodel().getManagedTypes() should work.
>
> @Gunnar Morling <gunnar at hibernate.org> does it make sense to you too?
>
> --
> Guillaume
>
>
>
More information about the hibernate-dev
mailing list