How can i get the java class from Hibernate ClassMetaData
I'm using the following code to get all ClassMetaData from the sessionFactory.
...
Map allClassMetadata = getSessionFactory().getAllClassMetadata();
Set<String> entityNames = allClassMetadata.keySet();
for(String entityName : entityNames) {
ClassMetadata classMetaData = (ClassMetadata)allClassMetadata.get(en开发者_C百科tityName);
Class entityClass =
}
...
Is it possible to retrieve the according java class. I've seen the method getMappedClass(EntityMode mode)
. But what does entitymode mean ?
You are right, put getEntityMode( EntityMode.POJO )
. There are a few Entity modes that can be used to mapping to things other than POJOs such as XML or Maps.
As of 2016 (Hibernate 5.2), getAllClassMetadata
is deprecated.
I guess this could be used instead:
Set<EntityType<?>> entities = sessionFactory.getMetamodel().getEntities();
List<?> classes = entities.stream()
.map(EntityType::getJavaType)
.filter(Objects::nonNull)
.collect(Collectors.toList());
精彩评论