[[appendix-legacy-bootstrap]]
== Legacy Bootstrapping

The legacy way to bootstrap a SessionFactory is via the `org.hibernate.cfg.Configuration` object.
`Configuration` represents, essentially, a single point for specifying all aspects of building the `SessionFactory`: everything from settings, to mappings, to strategies, etc.
I like to think of `Configuration` as a big pot to which we add a bunch of stuff (mappings, settings, etc) and from which we eventually get a `SessionFactory.`

[NOTE]
====
There are some significant drawbacks to the legacy bootstrapping mechanism which led to its deprecation and the development of the new approach, which is discussed in  <<chapters/bootstrap/Bootstrap.adoc#bootstrap-native,Native Bootstrapping>>.

`Configuration` is semi-deprecated but still available for use, in a limited form that eliminates these drawbacks.
"Under the covers", `Configuration` uses the new bootstrapping code, so the things available there are also available here in terms of auto-discovery.
====

You can obtain the `Configuration` by instantiating it directly.
You then specify mapping metadata (XML mapping documents, annotated classes) that describe your applications object model and its mapping to a SQL database.

[source,java]
----
Configuration cfg = new Configuration()
    // addResource does a classpath resource lookup
    .addResource( "Item.hbm.xml" )
    .addResource( "Bid.hbm.xml" )

    // calls addResource using "/org/hibernate/auction/User.hbm.xml"
    .addClass( org.hibernate.auction.User.class )

    // parses Address class for mapping annotations
    .addAnnotatedClass( Address.class )

    // reads package-level (package-info.class) annotations in the named package
    .addPackage( "org.hibernate.auction" )

    .setProperty( "hibernate.dialect", "org.hibernate.dialect.H2Dialect" )
    .setProperty( "hibernate.connection.datasource", "java:comp/env/jdbc/test" )
    .setProperty( "hibernate.order_updates", "true" );
----

There are other ways to specify Configuration information, including:

* Place a file named hibernate.properties in a root directory of the classpath
* Pass an instance of java.util.Properties to `Configuration#setProperties`
* Via a `hibernate.cfg.xml` file
* System properties using Java `-Dproperty=value`

== Migration

Mapping Configuration methods to the corresponding methods in the new APIs.

|===
|`Configuration#addFile`|`Configuration#addFile`
|`Configuration#add(XmlDocument)`|`Configuration#add(XmlDocument)`
|`Configuration#addXML`|`Configuration#addXML`
|`Configuration#addCacheableFile`|`Configuration#addCacheableFile`
|`Configuration#addURL`|`Configuration#addURL`
|`Configuration#addInputStream`|`Configuration#addInputStream`
|`Configuration#addResource`|`Configuration#addResource`
|`Configuration#addClass`|`Configuration#addClass`
|`Configuration#addAnnotatedClass`|`Configuration#addAnnotatedClass`
|`Configuration#addPackage`|`Configuration#addPackage`
|`Configuration#addJar`|`Configuration#addJar`
|`Configuration#addDirectory`|`Configuration#addDirectory`
|`Configuration#registerTypeContributor`|`Configuration#registerTypeContributor`
|`Configuration#registerTypeOverride`|`Configuration#registerTypeOverride`
|`Configuration#setProperty`|`Configuration#setProperty`
|`Configuration#setProperties`|`Configuration#setProperties`
|`Configuration#addProperties`|`Configuration#addProperties`
|`Configuration#setNamingStrategy`|`Configuration#setNamingStrategy`
|`Configuration#setImplicitNamingStrategy`|`Configuration#setImplicitNamingStrategy`
|`Configuration#setPhysicalNamingStrategy`|`Configuration#setPhysicalNamingStrategy`
|`Configuration#configure`|`Configuration#configure`
|`Configuration#setInterceptor`|`Configuration#setInterceptor`
|`Configuration#setEntityNotFoundDelegate`|`Configuration#setEntityNotFoundDelegate`
|`Configuration#setSessionFactoryObserver`|`Configuration#setSessionFactoryObserver`
|`Configuration#setCurrentTenantIdentifierResolver`|`Configuration#setCurrentTenantIdentifierResolver`
|===

  
