A persistence unit is a pairing of your domain model class mappings with a database connection, plus some other configuration settings. It is the starting point in JPA. The persistence unit is usually defined in persistence.xml.

   <persistence-unit name="HelloWorldPU">
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.use_sql_comments" value="true" />
  • The persistence.xml file configures at least one persistence unit; each unit must have a unique name.
  • Each persistence unit must have a database connection. Here you delegate to an existing java.sql.DataSource . Hibernate will find the data source by name with a JNDI lookup on startup.
  • A persistent unit has persistent (mapped) classes. You list them here.
  • Standard or vendor-specific options can be set as properties on a persistence unit. Any standard properties have the javax.persistence name prefix; Hibernate’s settings use hibernate .
  • The JPA engine should drop and re-create the SQL schema in the database automati- cally when it boots. This is ideal for automated testing, when you want to work with a clean database for every test run.
  • An application could have more than one persistence units.

Let's now see how to map an Object to a table.