You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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...
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:
The text was updated successfully, but these errors were encountered: