Learn how HIbernate works with our existing Java object model. The objects are marked as persistent, which means they will be recognized by Hibernate, but there might be objects that are not recognized by Hibernate.
- [Instructor] What is data persistence in Hibernate? Hibernate works with our existing Java object model. The objects are marked as persistent, which means that they will be recognized by Hibernate, but there might be objects that are not recognized by Hibernate. Only objects that contain instance variables can be stored in a relational database included in Hibernate. Objects can be in three states of persistence. The first state, the transient state, happens when objects exist in memory.
The database has no knowledge of the object. In order to persist this type of object, we must explicitly ask this session to save the object to the database. At that point, Hibernate assigns this object an identifier, and it's no longer in a transient state. From transient, it can become a persistent state. Persistent objects are objects that exist in the database, and they are managed by Hibernate. For example, if a property changes on a persistent object, Hibernate automatically updates the database.
The last state is called the detached state. These are objects that exist in the database, but Hibernate has lost a connection with them. A persistent object whose session has been closed is an example of a detached state. This object was persistent at one point in time and can be reattached to a valid Hibernate session when needed. It's important when you're programming your Java application that you're aware of the state of the objects you're working with in relation to the database.
- Installing Hibernate
- Adding a database connection for a project in NetBeans
- Setting up the configuration file
- Reverse engineering to discover object details
- Mapping the database to Java objects
- Saving, updating, and deleting an object
- Retrieving objects
- Using the CriteriaQuery
- Using HQL and native SQL queries
- Using aggregate methods in HQL