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

  1. For session factory we are extending LocalSessionFactoryBean.

    How can i get BootstrapServiceRegistryBuilder? where can i do applyIntegrator( MetadataExtractorIntegrator.INSTANCE ) ?

    getMetadataSources() in LocalSessionFactoryBuilder has BootstrapServiceRegistryBuilder but it is new instance.
    BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();

    How can i get the same instance and build upon that ?
    can i get it from metadataSources ?

    1. Try via the hibernate.integrator_provider configuration property. If that does not work, you need to inspect the Spring codebase and see how you can extend it or add support for setting the Integrator and send them a Pull Request.

  2. Thank you for an interesting article. I am using Spring LocalContainerEntityManagerFactoryBean and among other things, a lot of hibernate.* properties are being set in a HashMap with its setJpaPropertyMap method. I tried adding MetadataExtractorIntegrator.INSTANCE as the hibernate.integrator_provider property like you do above in the JPA bootstrap configuration. Yet the Database member variable stays null. How would you go about integrating MetadataExtractorIntegrator with LocalContainerEntityManagerFactoryBean? Any other ideas on getting database metadata when using Spring and JPA/Hibernate?

    1. Actually, it’s very easy. Just use the getJPAPropertyMap and pass the Integrator from a Java-based config. It’s much easier to do it using Java configurations rather than using XML (although it’s probably doable via XML too as long as the Integrator is passed as a bean)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.