Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a piece of maintenance code that should grant select privileges to a certain user at certain points of time:

grant select on A_DB.A_TABLE to READ_ONLY_USER;

I want to do this for all tables. I could use select * from tab in Oracle or show tables in MySQL to get the complete list and then move on like that.

But since I already have the javax.persistence.EntityManager Object at hand, I wondered if there is another way to get at all the mapped Entities, the Manager knows about (I am using Hibernate under the hood).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
452 views
Welcome To Ask or Share your Answers For Others

1 Answer

As of 2016 (Hibernate 5.2), both getAllClassMetadata and Configuration are deprecated.

I guess this could be used instead:

Set<EntityType<?>> entities = sessionFactory.getMetamodel().getEntities();

In special, to get the classes:

List<?> classes = entities.stream()
                          .map(EntityType::getJavaType)
                          .filter(Objects::nonNull)
                          .collect(Collectors.toList());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...