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

  Рет қаралды 6,416

CodeForgeYT

CodeForgeYT

4 жыл бұрын

In this video we will configure database connection with H2 using spring properties and autoconfiguration. Later we will learn how to use inheritance together with JPA and Hibernate in Java Spring Boot. We will create 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 TABLE_PER_CLASS strategy. In the final stage we will learn how to use inheritance in case of repositories which we will use to persist our entities into the database. Also we will check out how to handle mutliple beans implementation using @Primary annotation. We will track everything using H2 web console. Keep coding!
Joined table source code: github.com/codeforgeyt/jpa-in...
Joined table video: • Java Spring Boot - JPA...
Single table source code: github.com/codeforgeyt/jpa-in...
Single table video: • Java Spring Boot - JPA...
Superclass source code: github.com/codeforgeyt/jpa-in...
Superclass video: • Java Spring Boot - JPA...
Table per class source code: github.com/codeforgeyt/jpa-in...
Table per class video: • Java Spring Boot - JPA...
Follow //CodefForgeYT on:
FB: / codeforgeyt
Twitter: / codeforgeyt
GitHub: github.com/codeforgeyt
Instagram: / codeforgeyt

Пікірлер: 13
@deepusasidharan2012
@deepusasidharan2012 2 жыл бұрын
Excellent!!!
@CodeForgeYT
@CodeForgeYT 2 жыл бұрын
Many thanks!
@usermatti
@usermatti Жыл бұрын
Thank you Sir
@huseyinturkmen06
@huseyinturkmen06 Жыл бұрын
Really helpful video, i appreciate it!!
@nhatkhanhly7472
@nhatkhanhly7472 Ай бұрын
thank you Sir, Really helpful video! But i have a big problem with 'id' of each table. I want at each table, the id column is restarted at 1. Is it possible?
@benjamindagenais7461
@benjamindagenais7461 3 жыл бұрын
Thx for that video, really helpful. What if I have a service and controller Layer, would you create only one class for the 3 classes or you would also have one for each of the child and the parent like the repository ones?
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
Thanks for feedback! Great question. It really depends on the context. From one side it is nice to follow single responsibility principle and create separated controllers and services for each entity it will be also more versatile in case when some of the entities will have very specific behaviour From the other side it is possible to create some abstraction layer that can handle transformation. Then you can more or less create generic controller and service. So it is all about what you need and how your service will evolve in the future. Keep coding!
@chebbimehdi8576
@chebbimehdi8576 3 жыл бұрын
Hello CodeForge i noticed that deleteAll method deletes both tables of the subclasses is there a way to fix this incoherence?
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
Hi! Probably yes. Depends what you want to achieve. Maybe table per class inheritance is not good for your specific case.
@chebbimehdi8576
@chebbimehdi8576 3 жыл бұрын
@@CodeForgeYT Ty for the reply and thank you for all your videos I did fix it by extending each subclass to Jpa itself will that cause a problem in the future if yes what do you advice me to do?
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
@@chebbimehdi8576 I cant see your code, so it is hard to say if it will cause any problems in the future. If it will, you can simply adapt it later. If you would like to get feedback about your code try on stackoverflow. You can share your code there and discuss it. Glad you like the videos! Keep coding!
@inwigilator5613
@inwigilator5613 2 жыл бұрын
NULL not allowed for column "ID"; SQL statement: I have @GeneratedValue Annotation
@CodeForgeYT
@CodeForgeYT 2 жыл бұрын
Do you have setter for your id field?
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН
Inside Out Babies (Inside Out Animation)
00:21
FASH
Рет қаралды 23 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 55 МЛН
لااا! هذه البرتقالة مزعجة جدًا #قصير
00:15
One More Arabic
Рет қаралды 10 МЛН
Table Per Class inheritance strategy in hibernate
10:32
KK JavaTutorials
Рет қаралды 5 М.
JPA/Hibernate Fundamentals 2023 - Lesson 8 - Entity Inheritance
41:45
Hibernate Tip : How to map multiple entities to the same table
5:23
Thorben Janssen
Рет қаралды 10 М.
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН