Java Spring Boot - JPA - Hibernate - H2 - Entities Inheritance Mapping - Joined Table Strategy

preview_player
Показать описание
In the first place we will configure database connection. Later we will learn how to use inheritance together with JPA and Hibernate in Java Spring Boot application. We will create abstract super class (parent class) and then two sub-classes (child classes) which will inherit all of the properties and mapping information from parent class. We will use @Inheritance annotation to specify strategy which we will use. This time it will be JOINED strategy. In our super class we will also use @Enumerated annotation to learn how to persist enums. In the final stage we will learn how to use inheritance in case of repositories which we will use to persist and delete our entities from the database. We will track everything using H2 web console. Keep coding!

Follow //CodefForgeYT on:
Рекомендации по теме
Комментарии
Автор

This video saved me SOOOO much trouble. This video was a godsend. Thank you so much!

ranaisrivastav
Автор

Hi, I have to implement similar case. In my Order class, I have list of Product class objects. Where Product is the base Entity with some common properties and Book and Apparel is the child class Entity which extends the Product class. Now while saving the Order using REST service and sending the list of products in JSON format, data is not getting saved in Book and Apparel table. Data is saved only in base table entity means in Product table only. pls help me. let me know how can i share my code snippet?

deepakrohilla
Автор

Best Video List about Spring Boot ever i seen yet

jahadulrakib
Автор

How can you add a infantry object to infantry table???

pescoder
Автор

It is so good explanation. Thank you for saving my time. I have one question, if I want to update knight to archer, what should I do? I tried creating new archer instance with old knight's primary key. Then I request save for updating, but new archer was created with ignoring old knight's primary key.

fjddjxd
Автор

For example, I just want to find all Archerys from repository. How can I do that? My repository extends InfantryRepository and both has a method which name is findAll().

GolFoxtrotAlpha
Автор

Great explanations but how can I retrieve all infantry

mossabseifelislemdehane
Автор

i have a question : does the child class inherit associations defined in the parent class ( meaning if the parent have a relationship with another class like one to many or many to many ) does it apply on the child class ?

msea
Автор

Can you help me please . I have almost the same relation between classes, except abstract parent:
@Entity Class A;
@Entity Class B extends A;
And method (A a){
repoA.save(a);
B b = new B();
repoB.save(b);
}
And I get double records in table A and one record in table B. How I can avoid double in A?

jqpzxhh
Автор

So when you select from Infantry how do you know if it's a knight or archer? Do you have to use instanceof?

giovanni.n
Автор

Thanks for this video .I tried this. it is works perfect but i want to ask you something. For example now infantry id=2 .
if we have another entity classes different from this, its id is starting from 3 not 1. How we can fix this problem?

muratalikistan
Автор

How do you use it with spring controller and sevice?

muaztastemel
Автор

Hi !
I just came across your tutorial, good job, everything is clear.
On the other hand, my problem is with the save function,
there you have saved the data manually,
what to do if the data comes from a client server like PostMan

Sorry for my English, I translate on google translate, Thank's !

djamalabdounassirharoun
Автор

I know I am missing the point, but I could not avoid to say that knight is not a type of infantry.

alissonnunes
Автор

Bad example
What different between ArcherRepository and KnightRepository ? Only name ? The truth is you can use KnightRepository to create both archer and knight. Why you have to create two repository ?

hieuvuduc
welcome to shbcf.ru