Hibernate

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is ORM?

ORM stands for Object Relational Mapping. It maps the object to the data stored in the database. It helps developers for data creation, data manipulation and data access.

What is Transaction Interface?

Transaction Interface : It provides methods for transaction management.

Implement Hibernate?

1) Create the persistent class. (POJO) 2) Create the mapping file for the persistent class (abc.hbm.xml) 3) Create the configuration file (hibernate.cfg.xml) The configuration file contains informations about the database and mapping file <mapping resource = "" />. 4) Create the class that retrieves or stores the persistent object.

How do you map Java Objects with database tables?

1) First we need to write java domain objects(beans with setter and getter) 2) Write hbm.xml, where we map java class to table and database columns to java class variables.

What is the general flow of Hibernate Communication with RDBMS?

1) Load the hibernate configuration file and create configuration object. It will automatically upload all hbm mapping files. 2) Create Session Factory from configuration object. 3) Get one session from this session factory. 4) Create HQL Query 5) Execute Query to get list containing Java objects.

What are the core interfaces of hibernate framework?

1) Session Interface 2) Session Factory Interface 3) Transaction Interface 4) Configuration Interface 5) Query and Criteria Interface

What is inheritance strategy in hibernate?

1) Table per concrete class 2) Table per hierarchy 3) Table per subclass

Persistent class with Annotations?

@Entity annotation marks this class as an entity. @Table annotation specifies the table name where data of this entity is to be persisted. If you don't use @Table annotation, hibernate will use the class name as the table name by default. @Id annotation marks the identifier for this entity. @Column annotation specifies the details of the column for this property or field. If @Column annotation is not specified, property name will be used as the column name by default.

What is HQL?

HQL is a mechanism to query, store, update and retrieve objects from a database.

What is Hibernate?

Hibernate is a framework that simplifies the development of java application to interact with the database using XML configuration files.

Elements of Hibernate Mapping File? (abc.hbm.xml)

Hibernate-mapping is the root element in the mapping file. <class> It is the sub-element of the hibernate-mapping element. It specifies the Persistent class. <id> It is the subelement of class. It specifies the primary key attribute in the class. <generator> It is the subelement of id. It is used to generate the primary key. There are many generator classes such as assigned (It is used if id is specified by the user), increment, sequence, native etc. <property> It is the subelement of class that specifies the property name of the Persistent class. ------ many to many association mapping

What is Table per concrete class?

In case of table per concrete class, tables are created as per class. But duplicate column is added in subclass tables.

What is Table per hierarchy?

In table per hierarchy mapping, single table is required to map the whole hierarchy, an extra column (known as discriminator column) is added to identify the class. But nullable values are stored in the table.

What is Table per subclass?

In this strategy, tables are created as per class but related by foreign key. So there are no duplicate columns.

What is Session Factory Interface?

Session Factory Interface : The application contains session instances from a session factory. There is a single session factory for the whole application. It holds second level cache. It is threadsafe.

What is Session Interface?

Session Interface : The session object provides an interface between the application and data stored in the database. It holds a first-level cache (mandatory) of data. Session interface provides methods to insert, update and delete the object. It also provides factory methods for Transaction, Query and Criteria. It is not thread-safe.

Generator classes in Hibernate?

The <generator> subelement of id used to generate the unique identifier for the objects of persistent class. All the generator classes implements the org.hibernate.id.IdentifierGenerator interface. The application programmer may create one's own generator classes by implementing the IdentifierGenerator interface. 1) Assigned : It is the default generator strategy if there is no <generator> element. 2) Increment : It generates the unique id only if no other process is inserting data into this table. It generates short, int or long type identifier. 3) Sequence : It uses the sequence of the database. if there is no sequence defined, it creates a sequence automatically e.g. in case of Oracle database, it creates a sequence named HIBERNATE_SEQUENCE.

Create the configuration file (hibernate.cfg.xml)?

The configuration file contains informations about the database and mapping file <mapping resource = "" />.

Advantages of Hibernate?

The main advantages of hibernate are: 1) It protects developers to write SQL commands. 2) A lot less code to write and it performs better than JDBC. 3) To fetch data from multiple tables is easy in hibernate framework. 4) The performance of hibernate framework is fast because cache is internally used in hibernate framework. 5) ORM framework generates database-specific SQL for you. 6) Eager Loading/ Lazy Loading.

Implement Hibernate with Annotations ?

There are same steps with annotations too but there is no hbm.xml file. 1) Create the persistent class. 2) Create the configuration file (hibernate.cfg.xml)


Kaugnay na mga set ng pag-aaral

EXW SECTION 103 Section 103 COMBAT LOGISTICS FUNDAMENTALS

View Set

Strategic Management Chapter 6-10 Quizzes

View Set

Windows Network Management - Unit 1 - Unit 8

View Set

HESI EAQ renal, urinary, and reproductive systems

View Set

OSHA 30 Module 20 Process Safety Management

View Set