hibernate Flashcards

1
Q

What is SessionFactory x 3

A

Provides the instance of Session.
Thread safe.
It holds the data of second level cache( not default).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Session? x 4

A

Maintains a connection between the hib and database.

It provides methods such as persist(), update(), delete(), load(), get() etc.

It is a factory of Query, Criteria and Transaction.

Not thread safe

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

SQL query vs HQL

A

Session.createSQLQuery

Session.createQuery

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can we add criteria to a SQL query

A

Session.createCriteria

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

session.save() vs session.persist()

A

returns Serializable vs void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

get() las load()

A

null | real| | always hit the db vs ObjectNotFoundException | proxy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

update() vs merge()

A

inside a session or error vs any time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

states of the object in hibernate

A

transient, persisted, detached

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Transient

A

Just created, no primary key (identifier), no session

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Persistent

A

A session is open, and you just saved, retrieved the instance in / from db.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Detached

A

If a session is closed. call lock() or update() to go back to persisted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Inheritance mapping strategies

A

Table per hierarchy | concrete class |subclass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Table per hierarchy

A

One table with discriminator column, annotations:

@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name=”type”,discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue

@DiscriminatorValue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Table per hierarchy

A

One table with discriminator column, annotations:

@Inheritance(strategy=InheritanceType.SINGLE_TABLE)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Table per class

A

Tables are created as per class. But duplicate column is added in subclass tables

@Inheritance(strategy =InheritanceType.TABLE_PER_CLASS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Table per subclass

A

Tables are created as per class but related by foreign key. So there are no duplicate columns.

@Inheritance(strategy=InheritanceType.JOINED)

17
Q

Mimic IS A vs Has A

A

@MappedSuperclass vs @Embeddable

18
Q

Hibernate associations

A

@One to One
@One to Many
@Many to One
@Many to Many

19
Q

Possible collection mapping in associations.

A

1 -*, -

20
Q

What is lazy loading in hibernate?

A

Default, improves performance, loads child objects on demand.

21
Q

First Level Cache vs Second Level Cache

A

enabled by default, session vs SessionFactory not default