Shared Flashcard Set

Details

Week 4 Hibernate
Week 4 Multivision HIbernate
34
Software
Undergraduate 4
05/08/2013

Additional Software Flashcards

 


 

Cards

Term
What is ORM?
Definition
ORM stands for Object Relational Mapping.
It is the automated persistence of objects in a Java applications in a relational database.
Term
What does ORM consist of?
Definition
ORM consists of 4 pieces:

API for basic CRUD operations

API to express queries referring to classes

Facilities for specifying metadata.

Optimization facilities:
dirty checking, lazy associations fetching.
Term
What are the ORM Levels
Definition
Pure Relational (stored procedure)

Light Objects Mapping (JDBC)

Medium Object Mapping

Full Object Mapping
(composition, Inheritance, polymorphism, persistence by reach-ability)
Term
What is Hibernate?
Definition
Hibernate is a pure object relational mapping and persistence framework that allows us to use POJOS to relational database tables using XML configuration files. Its purpose is to relieve the developer from a significant amount of relational data.
Term
Why do you need ORM tools like Hibernate?
Definition

 

The main advantage of ORM like hibernate is that it shields the developer from messy SQL statements.

 

  • Improved Productivity
  • High level obejct-oriented API
  • Less Java code to write
  • No SQL to write
  • Improved Perfromance
  • Sophisticated Cache
  • Lazy Loading
  • Eager Loading 
  • Improved Maintainability
  • Less code to write
  • Improved Portability
  • ORM Framework generates data specific SQL for you
Term
What Does Hibernate Simplify?
Definition

Hibrenate Simplifies:

  • Saving and retrieving domain objects
  • making database column and name changes
  • Centralizing pre save and post retrieve logic
  • Complex Joins for retrieving related items
  • Schema creation from object model 
Term
What is the need for the hibernate xml mapping file?
Definition

The Hibernate maping file tells hibernate which tables and columns to us , load and store objects. 

 

It will conatain:

  • DTD
  • Class elements Identifier mapping and generation
  • Property Mapping 
  • Associations (one to many, many to many)
Term
What are the important tags of the hibernate.cfg.xml?
Definition
  • DTD 
  • JDBC Configurations
  • Dialect (Sql speific to a database)
  • Connection pool size
  • Database generation automation
  • File/class mapping

 

Term
What are the core interfaces of the hibernate framework
Definition
  • Session
  • SessionFactory
  • Configuration
  • Transaction
  • Query and Criteria
Term
What role does the Session Interface play?
Definition

The Session interface is used by hibernate applications. It is a single threaded, short lived object that represents a converation between teh application an persistent store. It allows you to creat  query objects to retreive persisten objects.

 

Session session = sessionFactory.openSession();

 

Session interface role:

  • Wraps JDBC connection
  • Factory for Transaction
  • Holds a mandatory  first level  cache of persistent objects used when  navigating the oject graphs or looking the objects up by identifier. 
Term
What role does the SessionFactory interface play in Hibernate?
Definition

This application obtains the Session instances from a SessionFactory. There is typically one session factory  for the whole application created during initialization. The session factory  caches generate  SQL stateents and other mapping metadata that Hiberante uses at runtime. It also holds cached datat that has been read in one unit  of work and may be reused in a future unit of work. 

 

SessionFactory sessionFactory = configuration.buildSessionFactory();

Term
What is the general flow of Hibernate configuration with RDBMS?
Definition
  • Load the Hiberanate configuration file. It will automatically load the mapping files.
  • Create SessionFactory form configuration object.
  • Get a session from this session factory.
  • Create HQL Query
  • Execute Query to get list containing Java objects

 

Term
What is HibernateQuery Language (HQL)
Definition
HQL is an oject oriented exension to SQL. CRUD ooperations can be performed with this flexible query mechanism
Term
How do you map java objects with database tables
Definition
  • Create java domain objects (pojos with getters and setters).
  • Write hbm.xml file to map classes to a table, database columns to Java class variables. Can also use annotations.

 

Term

What is the difference between load() and get()?

 

Definition
  • Only use the load method if you are sure that the object exisits. 
  • Load method will throw and exception.
  • Load returns a proxy by default. The database will not be hit until that proxy is invoked.
  • Use get if you are not sure that an object exists
  • Get will return a null if the unique id is not found in the database.
  • get () will hit datbase immediately.

 

Term

What is the differene between merge and update?

 

Definition
Use update wehn you are sure that the session deos not contain an already persistent instance  with the same identifier. Use merge when  you want to merge you modifications any time whithout consideration of the state of the session
Term
How do you define sequence generated primary key in hibernate.
Definition
The generator tag or GeneratedValue annotation tag SEQUENCE_NAME
Term
Define cascade and inverse option in one to many mapping
Definition
  • Cascade- enable operations to cascade to child entities.
  • cascade = "all|none|save-update|delete|all-delete_orphan"
  • inverse- mark this collection as "inverse" end of the bidirectional association
  • inverse ="true|false"



Essentially inverse indicates which end of the relationship should be ignored. so when perstisting a parent who has a collection of children. should you ask the parent  for a list of children or aks the children who that parents are? 

Term
What do you mean by Named- SQL Query
Definition
Named SQL Statements are defined in the mapping xml document and are called whenever required.
Term
How do you invoke a store proceedure?
Definition
Stored proceedures are difined in the xml mapping document and called when required.
Term
Explain Criteria API
Definition
Criteria API is a simplified API for retreiving entities by composing Criterion objects. This is a very convienient approach for functionalities liek "search" screens where  there is a variable number of conditions to be placed upon the result set.
Term
How do you swith between databases in Hibernate?
Definition
  • Change the driver properties in the configuration file.
  • Change the dialect in the configuration file to match the database.
  • Use appropriate Driver Jar File.
  • You do not have to alter the Java code.
Term
How do you enable the view of Hibernate generated SQL statements?
Definition

In the hibernate config file:

property name ="show _sql"> true </property

Term
What is the difference between sorted and ordere collections in Hibernate?
Definition
  • A sorted collection is a collection that is sorted by using the collections framework. The sorting occurs in the the memory of the JVM which is running Hibernate after data is being read from the database using a comparator.
  • If collection is not large this is a very efficient way of sorting
  • Order collection is sortin by specifying the order-by clause for sorting.
  • If your collection is very large this would be the efficient way to sort

 

Term
What are the Collection types in Hibernate
Definition

Bag

Set

List 

Array 

Map

 

Term
What are the ways to express joins in HQL
Definition

There are 4 ways of expressing  inner and outer joins. 

 

  • an implicit association join
  • an ordinary join form in the FROM clause
  • a fetch join in teh FROM clause
  • a theta style join in the WHERE clause
Term
What is Hibernate proxy?
Definition
The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return GGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked
Term
What is the use of dynamic-insert and dynamic update attributes in a class mapping?
Definition
The Criterion API is for retrieving entities by composing criterion objects.


Dynamic-update (defaults to false) Specifies that UPDATE SAL should be generated at runtime and contain only columns that have a changed value.

dynamic-insert (defauls to false) Specifies that the INSERT SQL should be generated at runtime and only contain values that are not null
Term
What is a fetching strategy?
Definition
A fetching strategy is the strategy that Hibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O?R mapping metadata or overridden by a particular HQL or Criteria query
Term
What is automatic dirty checking
Definition
Automatic dirty checking is a feature that saves us the effort of explicitly asking Hibernate to update the database when we modify the state of an object inside a transaction.
Term
What is transaction write behind?
Definition
Hibernate uses a sophisticated algorithm to determine efficient ordering that avoids database foreign key constraint violations but still sufficiently predictable to the user. This feature is called transactional write behind.
Term
What is the callback interface?
Definition
They allow the application to receive a notification when something interesting happens to an object. Perhaps a deletion or insertion. This is not mandatory to use but is useful for logging and other purposes
Term
What are the instance states of hibernate?
Definition
Transient - not associated with any data.

Persistent - associate with data.

Detached- no longer associated with data.
Term
What are three types of inheritance models in Hibernate?
Definition
Table per class hierarchy

Table per subclass

Table per concrete class
Supporting users have an ad free experience!