-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ecb7a29
commit 71b78c3
Showing
8 changed files
with
1,537 additions
and
0 deletions.
There are no files selected for viewing
1,377 changes: 1,377 additions & 0 deletions
1,377
hibernate-inheritance3-tableperclass/DEMO_INFORMATION_SCHEMA_CATALOGS.sql
Large diffs are not rendered by default.
Oops, something went wrong.
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,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.6.0</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>ru.sysout</groupId> | ||
<artifactId>inherit1</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>inherit1</name> | ||
|
||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
hibernate-inheritance3-tableperclass/src/main/java/ru/sysout/SpringDataJpaApplication.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,38 @@ | ||
package ru.sysout; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import ru.sysout.dao.CustomerRepository; | ||
import ru.sysout.model.Customer; | ||
import ru.sysout.model.EmployeeCustomer; | ||
import ru.sysout.model.ExternalCustomer; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
@SpringBootApplication | ||
public class SpringDataJpaApplication { | ||
@Autowired | ||
private CustomerRepository customerRepository; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringDataJpaApplication.class, args); | ||
} | ||
|
||
@PostConstruct | ||
void init() { | ||
EmployeeCustomer employeeCustomer = new EmployeeCustomer(); | ||
employeeCustomer.setMonthsInCompany(10); | ||
employeeCustomer.setName("Petr"); | ||
customerRepository.save(employeeCustomer); | ||
|
||
ExternalCustomer externalCustomer = new ExternalCustomer(); | ||
externalCustomer.setSum(110); | ||
externalCustomer.setName("Vasya"); | ||
customerRepository.save(externalCustomer); | ||
|
||
Customer customer=new Customer(); | ||
customer.setName("ldld"); | ||
customerRepository.save(customer); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
hibernate-inheritance3-tableperclass/src/main/java/ru/sysout/dao/CustomerRepository.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,8 @@ | ||
package ru.sysout.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import ru.sysout.model.Customer; | ||
|
||
public interface CustomerRepository extends JpaRepository<Customer, Long> { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
hibernate-inheritance3-tableperclass/src/main/java/ru/sysout/model/Customer.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 ru.sysout.model; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@Entity | ||
@Inheritance( | ||
strategy = InheritanceType.TABLE_PER_CLASS | ||
) | ||
public class Customer { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE) | ||
private long id; | ||
private String name; | ||
|
||
public Customer(String name){ | ||
this.name =name; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
hibernate-inheritance3-tableperclass/src/main/java/ru/sysout/model/EmployeeCustomer.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 ru.sysout.model; | ||
|
||
import lombok.Data; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
@Data | ||
public class EmployeeCustomer extends Customer { | ||
private int monthsInCompany; | ||
} |
11 changes: 11 additions & 0 deletions
11
hibernate-inheritance3-tableperclass/src/main/java/ru/sysout/model/ExternalCustomer.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 ru.sysout.model; | ||
|
||
import lombok.Data; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@Data | ||
@Entity | ||
public class ExternalCustomer extends Customer { | ||
private long sum; | ||
} |
9 changes: 9 additions & 0 deletions
9
hibernate-inheritance3-tableperclass/src/main/resources/application.yml
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,9 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:postgresql://localhost/inherit | ||
username: postgres | ||
password: qqq | ||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: create |