Skip to content

Hibernate5 metadata access [SPR-13710] #18285

Closed

Description

@spring-projects-issues

Koen Serneels opened SPR-13710 and commented

In Hibernate4 accessing the metadata was always possible on a live SessionFactory (SF) by for example using org.hibernate.cfg.Configuration#getClassMappings. The metadata is interesting as it can be used for modifying properties of entities, exporting SQL scripts and so forth.

However, these helper methods have now been removed as of Hibernate5 in favor of a new bootstrap mechanism: the APIs for building the
org.hibernate.SessionFactory are now backed by builders like: org.hibernate.boot.registry.BootstrapServiceRegistryBuilder,org.hibernate.boot.MetadataBuilder and org.hibernate.boot.SessionFactoryBuilder

Unfortunately Spring's org.springframework.orm.hibernate5.LocalSessionFactoryBean configures the SF using the legacy style by eventually using org.hibernate.cfg.Configuration#buildSessionFactory(). While the internal impl of
this method has been changed by Hibernate to use the builder style as well, there is no 'intermediate' access (or hook if you like) foreseen to access for example the metadata builder. This means that after the SF is returned there is no (clean) way to access the metadata.

So the ideal solution would be to to change org.springframework.orm.hibernate5.LocalSessionFactoryBean to make use of the builders and foreseeing additional hook methods to customize each of the builders before they are actually build. Another (maybe easier) solution might be to keep on using org.hibernate.cfg.Configuration#buildSessionFactory(), but allow to pass MetadaSources and/or BootstrapServiceRegistry to the constructor of Configuration (at this time Spring depends on the no-arg constructor of Configuration, which internally creates these objects and hence no reference is possible afterwards)


Affects: 4.2.3

Reference URL: https://www.mail-archive.com/[email protected]/msg12865.html

Issue Links:

Activity

  1. spring-projects-issues commented on Dec 21, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've added setMetadataSources / getMetadataSources methods to LocalSessionFactoryBean, as well as a corresponding overloaded constructor to the underlying LocalSessionFactoryBuilder. This can be used to specify an external MetadataSources instance or to access the internally used one for customization purposes (simply through calling getMetadataSources at any time before SessionFactory initialization). I hope that works for you...

    Juergen

  2. spring-projects-issues commented on Sep 14, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Koen Serneels commented

    Hi Jürgen we migrated to 4.3 this week works like a charm, thanks.

  3. added
    in: data
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions