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

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024

ความคิดเห็น • 20

  • @SirSX3
    @SirSX3 ปีที่แล้ว

    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`

  • @gentlefocus
    @gentlefocus 4 ปีที่แล้ว +1

    @MappedSuperclass is sweet!

  • @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.

  • @dawednesru5353
    @dawednesru5353 3 ปีที่แล้ว +1

    Huge thank Sir!

  • @darvin3665
    @darvin3665 2 ปีที่แล้ว +1

    JpaRepository or CrudRepoditory? Thanks, super tutorial!!

    • @CodeForgeYT
      @CodeForgeYT  2 ปีที่แล้ว +1

      Depends what you need, one is sub type of another and has some more stuff

  • @miguelangelmesacordoba2058
    @miguelangelmesacordoba2058 2 ปีที่แล้ว +1

    super clear , thx

  • @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 3 ปีที่แล้ว

    What is the difference between @MappedSuperClass and @Embeddable? I see that both of them do the same work, isn't it?

  • @Vinialves
    @Vinialves 4 ปีที่แล้ว +1

    tanks !

  • @МихаилГончаров-й3щ
    @МихаилГончаров-й3щ 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      I think its not possible to use it with @MappedSuperclass