As you saw in Chapter 3, you must configure Hibernate before you can use it. The configuration is represented by an object of type org.hibernate.Configuration
. This object wraps all of the configuration settings and is used in the next step for building a SessionFactory
object. (We'll discuss a useful strategy for creating the SessionFactory
at the end of this chapter.) To configure Hibernate, you first need to instantiate a configuration object:
Configuration cfg = new Configuration();
The actual configuration settings can be divided into two parts:
Hibernate properties: These include all of the database-related properties that Hibernate should consider while connecting to the database, as we saw earlier.
Hibernate mappings: These are XML documents that define the mapping of the entity classes to the database tables. You'll see a lot more on Hibernate mappings in Chapter 5 and Chapter 6.
Once you have instantiated a Configuration
object, there are two ways to configure...