Skip to content

Instantly share code, notes, and snippets.

@gbadner
Created April 26, 2011 22:37
Show Gist options
  • Save gbadner/943347 to your computer and use it in GitHub Desktop.
Save gbadner/943347 to your computer and use it in GitHub Desktop.
Process for building SessionFactory
Build ServiceRegistry
---------------------
Map config = ...;
A) ServiceRegistry serviceRegistry =
new ServiceRegistryBuilder( config )
...
.buildServiceRegistry();
B) ServiceRegistry serviceRegistry =
new ServiceRegistryBuilder()
.setConfigurationData( config )
.setOption( Environment.SHOW_SQL, true )
.buildServiceRegistry();
Questions:
1) Will there need to be a Jpa-specific ServiceRegistry (e.g., configured w/
JPA-specific listeners?
2) Emmanuel suggested using something like the following to set the default
services for JPA:
JPAWasher.wash(builder);
GB: JPAWasher would live in a different package, so ServiceRegistryBuilder
would have to have public setters (maybe OK for a builder).
Build MetadataSources:
----------------------
MetadataSources sources =
new MetadataSources( serviceRegistry )
.addAnnotatedClass( Order.class )
.addResource( "OrderLine.hbm.xml" )
...;
1) Does it make sense that MetadataSources could have some resources using
hibernate-mapping-4.0.xsd and others using orm_2_0.xsd?
2) Should there need to be a JpaMetadataSources?
Build Metadata:
---------------
A) Metadata metadata =
sources
.getMetadataBuilder()
.setNamingStrategy( namingStrategy )
... // other config stuff
.build();
B) Metadata metadata =
new MetadataBuilder()
.setNamingStrategy( namingStrategy )
... // other config stuff
.build( sources );
(makes it absolutely clear that the namingStrategy is
associated with the MetadataBuilder, not w/ MetadataSources)
C) Metadata metadata = sources.buildMetadata( new NamingStrategy() );
(this is OK if there's no need for a MetadataBuilder)
(also allows metadata to be built from the same source multiple
times using different naming strategies)
1) Would there be a need for a JpaMetadataBuilder? If there is a
JpaMetadataSources or some other way to indicate "jpa" sources, then
A) could get the JpaMetadataBuilder.
Build SessionFactory:
---------------------
SessionFactory sf = metadata.buildSessionFactory();
@jpav
Copy link

jpav commented Apr 27, 2011

I like that. Better idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment