-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: spring data jpa - InheritanceType.JOINED
- Loading branch information
Showing
9 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
spring-data-jpa/src/main/java/com/example/demo/controller/dto/joined/GetJoinedAlbumDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.demo.controller.dto.joined; | ||
|
||
import com.example.demo.domain.joined.JoinedAlbum; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class GetJoinedAlbumDto { | ||
private long id; | ||
private String name; | ||
private int price; | ||
private String artist; | ||
|
||
public GetJoinedAlbumDto(JoinedAlbum entity) { | ||
this.id = entity.getId(); | ||
this.name = entity.getName(); | ||
this.price = entity.getPrice(); | ||
this.artist = entity.getArtist(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
spring-data-jpa/src/main/java/com/example/demo/domain/joined/JoinedAlbum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.demo.domain.joined; | ||
|
||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@Getter | ||
@ToString | ||
@NoArgsConstructor | ||
@DiscriminatorValue("A") | ||
public class JoinedAlbum extends JoinedItem { | ||
|
||
private String artist; | ||
|
||
public JoinedAlbum(String name, int price, String artist) { | ||
super(name, price); | ||
this.artist = artist; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
spring-data-jpa/src/main/java/com/example/demo/domain/joined/JoinedBook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.demo.domain.joined; | ||
|
||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
|
||
@Entity | ||
@DiscriminatorValue("B") | ||
public class JoinedBook extends JoinedItem { | ||
|
||
private String author; | ||
} |
26 changes: 26 additions & 0 deletions
26
spring-data-jpa/src/main/java/com/example/demo/domain/joined/JoinedItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.demo.domain.joined; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Entity | ||
@Getter | ||
@ToString | ||
@NoArgsConstructor | ||
@Inheritance(strategy = InheritanceType.JOINED) | ||
@DiscriminatorColumn(name = "DTYPE") | ||
public abstract class JoinedItem { | ||
|
||
@Id @GeneratedValue | ||
private long id; | ||
|
||
private String name; | ||
private int price; | ||
|
||
public JoinedItem(String name, int price) { | ||
this.name = name; | ||
this.price = price; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
spring-data-jpa/src/main/java/com/example/demo/domain/joined/JoinedMovie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.demo.domain.joined; | ||
|
||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
|
||
@Entity | ||
@DiscriminatorValue("M") | ||
public class JoinedMovie extends JoinedItem { | ||
private String director; | ||
} |
7 changes: 7 additions & 0 deletions
7
spring-data-jpa/src/main/java/com/example/demo/repository/joined/JoinedAlbumRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.demo.repository.joined; | ||
|
||
import com.example.demo.domain.joined.JoinedAlbum; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface JoinedAlbumRepository extends JpaRepository<JoinedAlbum, Long> { | ||
} |