Skip to content

Hibernate5 metadata access [SPR-13710] #18285

Closed
@spring-projects-issues

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/hibernate-dev@lists.jboss.org/msg12865.html

Issue Links:

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions