@EntityHibernate uses Sun's EJB3 Annotation standard to map persistent Objects. Because of this, all Hibernate Objects are treated as Entity Beans. Note: Although Hibernate uses the EJB3 standard in this manner, the Objects do not need to be deployed in an EJB container to be used. An interesting benefit of this is that no modifications would be required for this class to be used inside a J2EE compliant server as an Entity Bean .

@Id(generate = GeneratorType.AUTO)This annotation defines the primary key for this Object. The following key generators can be used for generating IDs: AUTO, TABLE, IDENTITY, SEQUENCE, or NONE.

@OneToMany (mappedBy = "employee")This annotation is used to define a one-to-many relationship with an other Object. The "mappedBy" field is the foreign key of the Object.

@OrderBy ("name")This annotation is used in combination with @OneToMany to define that the collection is to be ordered. In this example the collection will be ordered by the "name" field in the Task table.

@TransientBy default all functions inside an EJB are persistent, and therefore are mapped to a field in the database. However, in this case both the getCompletedTasks() and getToDoList() are not persistent fields.

.setProperty("hibernate.hbm2ddl.auto", "create")The "hibernate.hbm2ddl.auto" will reload the database tables every time the session factory is built. This is an useful method to test the data element structure. Programmers should remove this before deploying the program.

The CreateEmployee class is a simple program which creates and saves 5 new Employees, 15 completed tasks, 10 uncompleted yet assigned tasks, and two unassigned tasks. The program then outputs the information that is located in the database. This is included in the package to demonstrate how the Employee and Task classes are stored and retrieved from the database using Hibernate.

The last component for this example is the Hibernate configuration file, which is required for the communicate with the database. Information such as the database location, user-name, and password are entered in this file.