Java Spring Boot - JPA - Hibernate - H2 - Entities Inheritance Mapping - @MappedSuperclass

  Рет қаралды 10,291

CodeForgeYT

CodeForgeYT

Күн бұрын

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) which will be annotated with @MappedSuperclass. Then we will create two sub-classes (child classes) which will inherit all of the properties and mapping information from parent class. We will also 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!
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

Пікірлер: 20
@dawednesru5353
@dawednesru5353 3 жыл бұрын
Huge thank Sir!
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
You are welcome!
@miguelangelmesacordoba2058
@miguelangelmesacordoba2058 2 жыл бұрын
super clear , thx
@CodeForgeYT
@CodeForgeYT 2 жыл бұрын
Great to hear!
@gentlefocus
@gentlefocus 3 жыл бұрын
@MappedSuperclass is sweet!
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
Yes, it is! :)
@Vinialves
@Vinialves 3 жыл бұрын
tanks !
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
You are welcome!
@SirSX3
@SirSX3 9 ай бұрын
For anyone stumbling onto this: a better way to do the @Repository is to use `public interface ParentRepository extends JPARepository` and the child class repository will be `public interface ChildRepository extends ParentRepository`
@darvin3665
@darvin3665 Жыл бұрын
JpaRepository or CrudRepoditory? Thanks, super tutorial!!
@CodeForgeYT
@CodeForgeYT Жыл бұрын
Depends what you need, one is sub type of another and has some more stuff
@123-m2x
@123-m2x Жыл бұрын
How to filler frontend details to subclasses with considering super class 's attribute ? It mean from vehicle class, considering seats. How devide details to trunk and truck?
@edith0043
@edith0043 2 жыл бұрын
What is the difference between @MappedSuperClass and @Embeddable? I see that both of them do the same work, isn't it?
@johng.weller468
@johng.weller468 2 жыл бұрын
Is it considered a best practice to send a boolean as a parameter to the constructor like that? In my opinion, it is better to have a boolean to hold the status of the cab type(sleep cab or not) and enum with two values( e.g: enum truckCabType{NO_SLEEP_CAB, WITH_SLEEP_CAB} ) then the constructor will ask the parameter of type truckCabType instead of a boolean and will finally set the boolean internally depending on the received value; the class can have a probably method hasASleepCab() to return the boolean. Without the help of the IDE with the super useful parameter hints feature nobody will know what the "true" or "false" is for if the person who reviews the code doesn't check the method signature first. It's worth pointing that out given that people are relying heavily upon this kind of video to learn how to code so it is sometimes useful to show some best practices(or what I believe to be a best practice) while coding.
@user-wn3zk5sk4t
@user-wn3zk5sk4t 3 жыл бұрын
Hey there! Can I define associations(@ManyToOne, @ManyToMany, @OneToMany, @OneToOne) in @MappedSuperclass? I actually tried it, but the problem is when hibernate generates schema, it doesn’t add @Basic fields in inherited tables.Can I fix it, or should I use completely different approach(use some kind of @Inheritance, for instance)?
@CodeForgeYT
@CodeForgeYT 3 жыл бұрын
I think its not possible to use it with @MappedSuperclass
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 55 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 94 МЛН
Scary Teacher 3D Nick Troll Squid Game in Brush Teeth White or Black Challenge #shorts
00:47
The Best Mapping for Shared Technical Attributes With Hibernate
9:07
Thorben Janssen
Рет қаралды 1,5 М.
Composition vs. Inheritance with JPA and Hibernate
10:23
Thorben Janssen
Рет қаралды 6 М.
Spring Tips: Spring Modulith
37:39
SpringDeveloper
Рет қаралды 16 М.
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 55 МЛН