4 thoughts on “How to get access to database table metadata with Hibernate 5

  1. Thanks for creating a blog post for my question. I have one more requirement. If I want to get the entity class name to which the table is mapped, then using the same logic that you mentioned, is it correct if I do it like this as I want to return the Class object also.
    Eg: Class cls = Class.forName(table.getQuotedName());
    And if i want to get the entity variable names to which the columns are mapped, can I get it column.getQuotedName()?

      1. I see that getEntityBinding takes the entity name as string, I have the DB table name with me. Considering your example, where post_details is the table name that I have, I want to get the entity class (Eg: PostDetails.java) object.

        public Class getEntityClassByTableName(String tableName) {

        Class cls = null;
        for(Namespace namespace : MetadataExtractorIntegrator.INSTANCE.getDatabase().getNamespaces()) {

        for( Table table : namespace.getTables()) {
           if(table.getName().equals(tableName)) {
               //how can i get the entity class name as the Table class does not yield that to use the 
               //metadata.getEntityBinding() which you suggested.

        return cls;


      2. Take your time to study the API and you’ll find that you can get all EntityBindings from the Metadata. You can filter them by their associated getTable property. Good luck!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s