Databases and ORM Flashcards

(23 cards)

1
Q

What is java database connectivity(JDBC)

A

JDBC uses classes and attributes to manipulate the database, but the
content of the database is not manipulated as objects and attribute

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

What are the pros of java database connectivity

A

o database accessible from Java
o handle errors with Exception handling

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

What are the cons of java database connectivity

A

o SQL statements in the code
o complexify the program
o mapping between object and tables needs to be specified and
maintained

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

What is Object-Relational Impedance Mismatch

A

Object-Relational Impedance Mismatch’ is just a fancy way of saying that
object models and relational models do not work very well together.
RDBMSs represent data in a tabular format , whereas object-oriented
languages, such as Java, represent it as an interconnected graph of objects.
Loading and storing graphs of objects using a tabular relational database
exposes us to […] mismatch problems.

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

What is object relational mapping(ORM)

A

ORM = a task
- converting OO concepts to relational databases concepts
- input: a domain model (class diagram)
- output: relational schema

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

How do we specify and use our mapping in our java application?

A

By use of Jakarta and hibernate

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

what is jakarta persistemce API(JPA)

A

▪ specification (not a tool -> guidelines)
▪ removes the burden of thinking relationally in Java code

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

What is hibernate

A

It’s the implementation of JPA (= JPA provider)
It rely on ORM to simplify the persistence layer
▪ e.g., manipulating data as objects, without JDBC or SQ

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

What is the purpose of JPA (Jakarta Persistence API)?

A

JPA simplifies the persistence layer by allowing developers to manage relational data as Java objects using annotations, an EntityManager API, and JPQL (object-based query language)

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

Is JPA a tool or a specification?

A

JPA is a specification (guidelines). Tools like Hibernate provide its implementation

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

What is Hibernate in relation to JPA?

A

Hibernate is a JPA provider (implementation). It manages ORM and allows data to be manipulated as Java objects, removing the need for JDBC/SQL code

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

What annotation makes a class persistable in JPA?

A

@Entity

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

How do you mark the primary key in JPA?

A

With @Id. Optionally, use @GeneratedValue to auto-generate unique primary keys

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

Which JPA annotations handle associations?

A

One-to-Many: @OneToMany / @ManyToOne

Many-to-Many: @ManyToMany

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

What is the EntityManager API in JPA?

A

An API that provides CRUD operations (Create, Read, Update, Delete) without writing JDBC or SQL code

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

What is JPQL, and how does it differ from SQL?

A

JPQL (Java Persistence Query Language) is like SQL but operates on objects, attributes, and relationships, not on tables and columns

17
Q

Give an example JPQL query.

A

SELECT s.name FROM Student s
SELECT o FROM Offering o WHERE o.courseID = “ECSE321”

18
Q

What are the main steps of using JPA persistence?

A

1.Annotate classes for persistence (@Entity, @Id, etc.).
2.Manage data with EntityManager (CRUD).
3.Query with JPQL

19
Q

What is Spring Data JPA?

A

A framework built on top of JPA that reduces boilerplate by providing repositories and auto-generated query methods

20
Q

What does CrudRepository provide in Spring Data JPA?

A

Standard CRUD methods: save, findOne, findAll, count, delete, exists

21
Q

What are the two ways to define query methods in Spring Data JPA?

A

1.With @Query annotation (using JPQL).
2.Automatically derived from method names (e.g., findByLastOrFirst)

22
Q

Give an example of a custom query with @Query.

A

@Query(“SELECT o FROM Offering o JOIN o.course c WHERE c.courseId = ?1”)
Collection<Offering> findAllOfferingOfCourse(String courseId);</Offering>

23
Q

What problem does ORM (and JPA/Hibernate) solve compared to JDBC?

A

It solves the object-relational impedance mismatch: the difficulty of mapping object-oriented models (Java) to relational models (tables)