Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate5 metadata access [SPR-13710] #18285

Closed
spring-projects-issues opened this issue Nov 20, 2015 · 2 comments
Closed

Hibernate5 metadata access [SPR-13710] #18285

spring-projects-issues opened this issue Nov 20, 2015 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 20, 2015

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:

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

Koen Serneels commented

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants