Hibernate Flashcards
What is Hibernate?
Hibernate is an Object Relationship Mapping Framework/Tool. It allows a program to map a class to a relational database. In doing so, the programmer creates a sessionfactory. The sessionfactory contains the connection info for the database, as well as the driver, and dialect. You can map files either by a mapping file, or by JPA annotations in the classes you want mapped.
What does it abstract?
Hibernate is an abstraction of JDBC.
How do you configure Hibernate?
- You can configure hibernate via a configuration xml, or programmatically. In the xml, you would set up the session factory with the sessionfactory tag. It would contain all the info for your database, like driver, dialect, connection info, and any and all mappings.
Why do you need ORM tools like Hibernate?
You need ORM tools like Hibernate because it would take a long time to setup all of the DAOs in a JEE project/environment. Because it abstracts JDBC, it sets up all of your daos after you map your classes. Hibernate can even create the database for you.
What is ORM?
ORM stands for Object Relational Mapping. It is a way to relate a programs beans to a relational database. You can you annotations like @Id to specify that a particular variable is the ID for that table and so on.
What does ORM consists of?
ORM consists of taking an existing bean, and mapping it to a relational database. To start, you would annotate the class with the @Entity annotation. You would then annotate the class @Table and give it a table name. As for the variables of the class, you must annotate the ID with @Id, and all of the other variables with @column.
What are the ORM Levels?
The ORM levels are: Pure Relational Mapping - stored procedure Light ORM Mapping - like JDBC Medium ORM Mapping Full ORM Mapping alike Hibernate
What are the Hibernate Object States?
The Hibernate Object States are:
Transient - Object exists outside of session and the row
Persistent - Object in the session that represents a row in the database
Detached - Object is removed from the session, any actions on the object are not saved to the database.
What are Application Transactions?
Application transactions are any action that needs to modify data stored in the database. There are different ways of ensure ACID properties of these transactions.
What is HQL?
HQL is Hibernate Query Language. HQL is hibernates version of SQL. It is made to act more like OOP.
What is Native SQL?
Native SQL is a way of running regular SQL queries in Hibernate
What is the Criteria API? How does it differ from HQL?
The Criteria API is one main interfaces of Hibernate. It allows for programmatic querying of the database. They use restrictions and projections. Restrictions act like a where clause, while projections act like aggregate functions. Criteria API differs from HQL in that it is fully programmatic. HQL is still structured like SQL. It just understands OOP principles..
What do you need to include in the hibernate.cfg.xml file?
- The Hibernate config file must have all the details to setup the sessionfactory. These details are the connection info, dialect, and driver. It must also have all mappings in a mapping tag.
- Driver
- Dialect
- Username
- Password
- URL
- Link to mapping file
What is Hibernate.hbm2ddl?
Hibernate.hbm2ddl is a property you can set in the cfg that will tell hibernate whether or not to make the database. It is best not to use this in anything that isn’t a development environment.
What is HBM?
HBM stands for Hibernate Mapping. This tells hibernate how to map a given object to a relational database.