Home > Software engineering >  Retrieve table hierarchie from Hibernate
Retrieve table hierarchie from Hibernate

Time:08-27

Now and then I come into the situation that I have to display the table hierarchie of a database for further operations, currently in a data migration project where I have to treat "leaf tables" (tables which are leafes in the table dependency tree) in a different way.

I've always wanted to use Hibernate's meta information to retrieve and display the table dependency tree, but never knew how to approach the problem.

So can anyone give me feedback on whether Hibernate provides an API to do this? I am not asking for a complete solution, the information if there is an API and what it is called is absolutely sufficient.

I want to solve the following questions:

  • Which tables are in the database?
  • Is a given table a root table (not dependant from other tables)?
  • Is a given table a leaf table (dependant from other tables but no table is dependant from the given table)?
  • Which tables are dependant from the given table?
  • On which tables does the given table depend?

I know how to retrieve the mapping between entities and tables: How to discover fully qualified table column from Hibernate MetadataSources , but I want the relationship between the tables.

CodePudding user response:

In a custom MetadataContributor you can access metadataCollector.getDatabase() which exposes the full relational model to you. You just have so save that into a static volatile variable and then access it later on in your app to do whatever you want to do with it.

  • Related