Based on that transcript "Instructor: In this video

we'll cover the JPA development process.

Here's the JPA development process.

Our to-do list.

The first thing we need to do is annotate the Java class,

and then we need to develop the Java code

to perform the database operations.

Let's just say JPA.

As mentioned, Hibernate is the default JPA implementation

in Spring Boot.

Going forward in this course, I'll simply use the term JPA

instead of saying JPA Hibernate

or Hibernate JPA, I'll simply say JPA

because we know that by default,

Hibernate is used behind the scenes.

For terminology, we have this term called entity class,

and that's a Java class that is mapped to a database table.

And here we'll make use of this object

to relational mapping.

Again, mapping a Java class to a database table.

We'll have this Java class called student

that has four fields:

id, firstName, lastName, and email.

We'll make use of JPA

and we'll map it to a given database table called student.

It has four columns:

id, first_name, last_name, and email.

And notice you're the first_name

and the last_name.

So we need to kind of provide mappings between the two.

At a minimum, the Entity class must be annotated

with the @Entity annotation.

Also, it must have a public

or protected no argument constructor.

The class can have other constructors,

but again, as a minimum, you must have a public

or protected no arc constructor.

And now just a quick refresher here on constructors in Java.

Now remember when you're using constructors in Java,

if you don't declare any constructors,

then Java will provide a no argument constructor for free.

However, if you declare constructors

with arguments in your class,

then you do not get a no argument constructor for free.

In this case, you have to explicitly declare

a no-argument constructor.

So again, be aware of that.

And I'll kind of go through examples

of the coding for this in this course.

With our Java annotations, we have two steps here.

One is mapping a class to a database table

and then mapping the fields to database columns.

Let's get started here with step one

of mapping a class to a database table.

So we have this class student,

we have this database table called student.

Here, I make use of this entity annotation for my class,

and then I make use of the table annotation

and I give (name="student").

That's the name of the database table

that we're actually mapping this given Java class to.

And then in step two we map fields to database columns.

Here we have this class called Student

And we need to map these given fields

to the appropriate database columns.

And I can do that by making use of the column annotation.

You have @Column(name="id").

that's the name of the actual database column.

For the next field here.

First name have @Column(name="first_name").

So again, notice here the spelling.

There's different spellings here between the Java class

and the actual database column name,

and we annotate those accordingly.

One thing to be aware of here

is that the @Column annotation is actually optional.

You actually don't have to provide it.

So if not specified, the column name is the same name

as the Java field.

In general, I don't recommend this approach

because if you refactor the Java code,

like maybe refactoring the field name,

then it will not match the existing database columns.

And this is a breaking change and you need to go through

and update the database columns.

This may not be a big deal for a very small basic project

that you're working with on your own.

However, if you're working in a large company

working on an enterprise application at an MNC,

then you can't simply go

through and change database columns however you feel

because it could affect other teams within your company

that are using that given database.

So again, be aware of that.

So I normally don't recommend this approach,

but I wanted to let you know that it's available.

Also, the same applies to the @Table annotation.

If you don't provide the @Table annotation,

then the database table name is the same as the class.

Again, same thing applies here.

I don't normally recommend this.

I like to be explicit and annotate the class

and fields accordingly.

Here's another term here, primary key.

So the primary key uniquely identifies each row

in a table, must be a unique value,

and it cannot contain NULL values.

In the MySQL database, we can make use

of an auto increment.

So we can define our primary key

and then we can specify that it's an auto increment.

So here I have a little snippet here,

CREATE TABLE student.

We have this column id of type int.

We say it's NOT NULL

and then we specify AUTO_INCREMENT.

Behind the scenes, MySQL will keep track

of automatically incrementing this id

and make sure it's a unique value.

And also here at the line at the bottom for primary key,

we specify that our given column id

that this is the primary key for this given table.

And then, so in the JPA world,

we have to specify the actual primary key

or the identity here.

So we make use of this @Id annotation

and then we specify how this given id

or primary key, how the value generated.

Here I make use of generation type identity.

What I'm saying is that this id value will be generated

by the database and managed by the database.

There's no need for our code to manually try

and keep track of that given id.

It's a generated value.

Now, a bit more here on the ID generation strategies.

The first one here is GenerationType.AUTO.

That'll basically pick an appropriate strategy

for the particular database.

Next, we have this GenerationType.IDENTITY.

That's the one that we're using.

So we're gonna assign primary keys using the database

identity column or primary key column.

Another approach here is the GenerationType.SEQUENCE.

You can assign primary keys using a database sequence.

And next we have GenerationType.TABLE.

We assign the primary keys using an underlying database

table to ensure uniqueness.

And then finally, we have GenerationType.UUID.

Here we assign primary keys using a globally unique

identifier or UUID to ensure uniqueness.

In general, I recommend teams start out

by using the GenerationType.IDENTITY

and that should cover most of the use cases.

However, if you have very specific use cases,

you can apply some of the other generation types

based on your application requirements.

Alrighty, now bonus bonus,

we covered a lot of good stuff here.

You could say, "Hey, I went through

and I went through the docs

and I looked at all these other generation types.

They sound interesting,

but at my company, on our project, we have a very specific

requirement for generating the ID.

And nothing that JPA provides out

of the box matches our requirement."

Okay, no problem.

You can actually define your own custom generation strategy

for generating your ID.

You simply create a custom implementation

of this identifier generator interface.

You override the method or implement the method generate.

And again, inside of this generate method,

you provide your own custom business logic

or corporate logic here for actually generating a given ID.

So they basically give you an extension point

where you can create your own custom generation strategy

for creating your IDs.

Alrighty, this all looks pretty good.

Let's go ahead and move into the next video

and let's start mapping our class to a database table.

I'll see ya in the next video, yo, yo." before going to the next video can you explain all the concepts again to me because there are alot of stuff here going on