Revature Hibernate QC practice

Ace your homework & exams now with Quizwiz!

Important Annotations used for Hibernate Mapping

Example of some important Annotations: Entity Table Access Id Column Generated Value One to One One To Many Many to One Many To Many

session-factory is a tag in hibernate.cfg.xml True or False

False

What is a One-to-One association in Hibernate?

It is similar to the many-to-one association and the difference lies in the column that will be set as a unique one.

Non Repeatable read

Non Repeatable read occurs when a transaction reads the same row twice, and get a different value each time

ORM

OBJECT Relational Mapping

Important Interfaces of Hibernate

-Session -Session Factory -Transaction -Criteria -Query -Configuration

What are the ways to map classes hierarchies onto our database tables.

1. MappedSuperclass strategy: inheritance is only evident in the class, but not the entity model. 2. The Single Table strategy: creates one table for each class hierarchy. This is also the default strategy chosen by JPA if we don't specify one explicitly. 3. Joined Table - Using this strategy, each class in the hierarchy is mapped to its table. The only column which repeatedly appears in all the tables is the identifier, which will be used for joining them when needed. Each strategy results in a different database structure.

How do I relate entities? (Cardinality Mapping)

@OneToOne: Eagerly loaded @OneToMany: Lazily loaded @ManyToOne: Eagerly @ManyToMany: Lazily @JoinColumns: Foreign Key

Dirty Read

A Dirty read is the situation when a transaction reads a data that has not yet been commited

What is session used for?

A Session is used to get a physical connection with a database.

"Atomicity" means...

A single transaction either does everything it is supposed to, or nothing

Continuous integration is ____.

A) All of these B)The process of integrating code daily and verifying changes with incremental builds C)The process of integrating builds with another build in the cloud D)The process of integrating builds just before going live into production

A ______ defines when a Jenkins will begin a build.

Build trigger

What is Hibernate Framework?

An object-relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database. Abstract away JDBC No longer write SQL (unless we want to) we write hibernate Query Language Dialect-agnostic and object oriented query language We can even generate tables and other db objects like triggers and sequences With hibernate. (Code-first set up, but there also exist database-first setup)

L1 vs L2.

Both are types of caching L1: Applies to each session individually, cannot be configured, is default L2: Applies to a session factory, increases read operation performance, must be configured with ehcache

Difference between merge and Update

Both are used to transfer an object from a detached state to persistent state. In contrasts to merge() update can't lose any changes by calling it. Both the MERGE and UPDATE statements are designed to modify data in one table based on data from another, but MERGE can do much more. Whereas UPDATE can only modify column values you can use the MERGE statement to synchronize all data changes such as removal and addition of row.

Hibernate method: Close()

Close() : Close session by calling session.close() method, means End the session and releasing the JDBC Connection and clean up.

Transaction Isolation Levels in DBMS

Dirty Read Non Repeatable Read Phantom Read Read Uncommit

________ ensures the SQL only contains columns whose state have changed, and _________ ensures SQL only contains columns whose values are not null.

Dynamic-update, dynamic-insert

Difference between Eager and Lazy fetching

Eager fetching loads child records ahead of time, whereas lazy fetching only loads child records on-demand.

EHCache

Ehcache is an open source, standards-based cache that boosts performance, offloads your database, and simplifies scalability.

What does EC2 stand for?

Elastic Cloud Compute

What is the purpose of the Criteria interface?

Fully object-oriented programmatic query creation

HQL

Hibernate Query Language

What is hibernate configuration file?

Hibernate configuration file contains database specific configurations and used to initialize SessionFactory

What is hibernate mapping file?

Hibernate mapping file is used to define the entity bean fields and database table column mappings. We know that JPA annotations can be used for mapping but we can sometimes use XML for mapping in the hibernate cfg xml.

Hibernate exceptions

Hibernate's exceptions are all runtime. Lazy Initialization Exception: Trying to access a detached object. Query Syntax Exception: Trying to query a field that isn't mapped Annotation Exception: Specifies the wrong sequence order. Persistent Object Exception: When you try to insert PK when you also told it to be generated.

What is dirty checking in Hibernate?

In dirty checking, hibernate automatically detects whether an object is modified (or) not and need to be updated. As long as the object is in persistent state . Hibernate monitors any changes to the objects and executes sql.

What is One-to-Many association in Hibernate?

In this association, one object can be associated with multiple objects. The One-to-Many mapping is implemented using a Set Java collection that does not have any redundant element.

Hibernate SessionFactory is thread safe?

Internal state of SessionFactory is immutable, so it's thread safe. Multiple threads can access it simultaneously to get Session instances.

JPA

Java Persistence API

A _______ is the term used for a Jenkins build workflow that you configure for a project.

Job

Difference between Load and Get

Load: Will always return a proxy without hitting the database. If nothing is found it will throw an ObjectNotFoundException Get: It always hit the database and return the real object. If nothing is found it will return null

"Durability" means...

Once a tranaction commits, it must be permanent

sudo

Permanently elevates a user's permissions and runs proceeding commands as root.

Phantom Read

Phantom Read occurs when two same queries are executed, but the rows retrieved by the two, are different.

The REPEATABLE_READ isolation level allows which errors to occur?

Phantom Reads

The READ_COMMITTED isolation level allows which errors to occur?

Phantom and Non Repeatable read

@ID

Primary key

The ______ interface allows developers to write and execute HQL.

Query

Which isolation level is the fastest?

READ_UNCOMMITTED(Dirty Read)

The SQL standard defines four isolation levels :

Read Uncommited Read Committed Repeatable Read Serializable

The ____________ transaction isolation level addresses the dirty read concurrency issue.

Read uncommitted

Hibernate method: evict():

Removes the object from the session. This method is used to dissociate/disconnect the specified object from the session.

When using Criteria, _________ adds a WHERE clause, and _________ adds an aggregate function.

Restrictions, Projections

Difference between HQL and SQL.

SQL is concerned about the relationship that exists between two tables while HQL is concerned about relation between objects.

Difference between Save and Persist

Save() = returns id, will always create a new row even if detached. Persist() - returns nothing, will throw an exception if detached.

The ____________ transaction isolation level addresses none of the concurrency issues.

Serializable

What do you mean by SaaS?

Software as a Service

For EC2, which instance state will completely remove the instance and its backing store?

Terminate

What is Many-to-Many association in Hibernate?

The Many-to-Many element indicates the relation between one object to many other objects and column attribute is used to link intermediate columns. A Many-to-Many mapping is implemented using a Set Java collection that does not have any redundant element.

Query Interface

The Query interface allows you to perform queries against the database and control how the query is executed. Queries are written in HQL or in the native SQL dialect of your database.

Object States in Hibernate

These are the object states in Hibernate -Transient -Prersistent and -Detatched

Instantiating a SessionFactory should be done inside a try/catch block?

True

Configuration Interface

Used to create Session Factory, we specify metadata and location of db in file called hibernate.cfg.xml(separate entity from pom and web xml)

How do I map a class without annotations?

Using the hibernate mapping tags within the hibernate.cfg.xml file and [className].hbm.xml file

Hibernate method: Clear () :

When this method get called inside transaction boundry then all objects which are currently associate with particular session will be disconnected / clean or no longer associate with that Session instance. Therefore, after calling this method nothing will be performed on

What is a Many-to-One association in Hibernate?

Where one object can be associated with multiple objects.

@Table(name="TABLE_NAME")

You want to specify a name for a table you already have in the database. If you don't specify it'll name the table the same as the class. Put at the beginning of the Class.

A named query

a statically defined query with a predefined unchangeable query string. They're validated when the session factory is created.

What is Horizontal Scaling in computing?

affords the ability to scale wider to deal with traffic.

Criteria Interface

allows you to create and execute object-oriented criteria queries.

Persistent

associated with the hibernated session -Object has representation in the DB, and has an id value -In the scope of a hibernate session -Hibernate will detect any change made to an object in this state and will synchronize(update with db) the representation of that object at the end of the unit of work (TX)

What is the default loading for Hibernate collections

by default, lazy loading is enabled in Hibernate for collections

Session Interface

connection with the database. Through this interface we have various methods to programmatically interact with our database is session.get(), session.save(), session.update()...

@Column(columnName)

distinguishes the name of the column

Vertical scaling

essentially resize your server with no change to your code.

Transient

generally known for not being associated with the hibernate sessions When a object is never continued or related with any session, it's in transient state. Transient cases might be influenced diligent by calling save(), persist() or saveOrUpdate(). Steady examples might be influenced transient by calling to delete().

Which Hibernate configuration property is responsible for setting the driver?

hibernate.connection.driver_class

How can we have Hibernate write the generated SQL to the console?

property name=show_sql in hibernate.cfg.xml

Session methods.

session.openSession(); session.createCriteria(); session.createQuery(); session.createSQLQuery(); session.list(); session.beginTransaction(); session.commit(); session.rollback();

@GeneratedValue(...):

tells the value generated

SessionFactory Interface

used to create session, only one - singleton design pattern

Transaction Interface

used to manage transactions and maintain ACID-compliant interactions with the db

@Entity

used to tell Hibernate that the class needs to be mapped to a table in a database

Detached

was associated with hibernate sessions, but the session has been closed. -Object was persistent but session has been closed -Object in this state still has representation and id value in DB. -Can be brought back to the persistent state aka re-associated with a session to update

What is A.C.I.D?

• Atomicity: Is defined as either all operations can be done or all operation can be undone • Consistency: After a transaction is completed successfully, the data in the datastore should be a reliable data. This reliable data is also called as consistent data • Isolation: If two transactions are going on the same data then one transaction will not disturb the other transaction • Durability: After a transaction is completed, the data in the datastore will be permanent until another transaction is going to be performed on that data


Related study sets

Economics and environmental question - midterm

View Set

PrepU Chapter 48: Management of Patients with Kidney Disorders

View Set

Micro test 4 Respiratory system infectious diseases

View Set