2

I need to have a List of clasess that are Persistence Entities, I need have Entity Information, using Reflection API of JPA

I have the EntityManager, But I do not know if that is the way.

I want to do a generic logging for my Entities using a EntityListener. That works well, but I do not have the way to register the listener to all my entities.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
jrey
  • 2,163
  • 1
  • 32
  • 48

2 Answers2

2

Use the JPA2 MetaModel? It has assorted methods to see the entities (or managed types).

 Set<javax.persistence.metamodel.EntityType<?>> entityTypes = entityManagerFactory.getMetamodel().getEntities();
    for (javax.persistence.metamodel.EntityType entityType : entityTypes){
        logger.info(entityType.getName());
        logger.info(entityType.getJavaType().getCanonicalName());
        logger.info("******************************");
    }
jrey
  • 2,163
  • 1
  • 32
  • 48
Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
1

Take a look at Configuration#getClassMappings()

Returns: Iterator of the entity mappings currently contained in the configuration.

Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
  • Thanks Predrag, Configuration is a Hibernate class, right?, In my case this not works because I am using Eclipse Link and I want to do a JPA solution. – jrey Mar 02 '15 at 14:55
  • 1
    You tagged your question with Hibernate tag, that's why I posted this. I'll edit my answer if I find a JPA way to do this. – Predrag Maric Mar 02 '15 at 14:58
  • sorry!! sorry!, It is my mistake – jrey Mar 02 '15 at 15:04