{"id":128429,"date":"2024-11-21T10:37:00","date_gmt":"2024-11-21T08:37:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=128429"},"modified":"2024-11-18T10:58:56","modified_gmt":"2024-11-18T08:58:56","slug":"query-jpa-single-table-inheritance","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html","title":{"rendered":"Query JPA Single Table Inheritance"},"content":{"rendered":"<p>In Java Persistence API (JPA), inheritance mapping provides a way to map Java class hierarchies to database tables. Single Table Inheritance is one of the inheritance strategies where all entities in a class hierarchy are stored in a single database table. Although simple to implement, it requires a <code>discriminator column<\/code> to distinguish between various subclasses. Let us delve into understanding JPA inheritance with single table strategy, exploring how it allows different entity types to be stored in a single database table while distinguishing them using a discriminator column.<\/p>\n<h2><a name=\"section-1\"><\/a>1. Single Table Inheritance SubTypes<\/h2>\n<p>Single Table Inheritance is managed by using the <code>@Inheritance<\/code> annotation with <code>InheritanceType.SINGLE_TABLE<\/code>. In this approach, a single table is created to store all fields of both the superclass and subclasses. A discriminator column is used to identify the type of entity being stored. <\/p>\n<h2><a name=\"section-2\"><\/a>2. Code Example<\/h2>\n<h3>2.1 Setting up the Project and adding dependencies<\/h3>\n<p>We\u2019ll start by creating a Spring Boot project with the help of <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noopener\">Spring Initializr<\/a> and add the necessary dependencies. In the <code>pom.xml<\/code> file, add the following dependencies:<\/p>\n<pre class=\"brush:xml; wrap-lines:false;\">\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<h3>2.2 Setting up the Mock data<\/h3>\n<p>We will be using a PostgreSQL database running on Docker. Once the PostgreSQL database is up and running on Docker use the below SQL commands to create the mock data.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\n-- Create Database\nCREATE DATABASE test;\n\n-- Create Employee Table with Single Table Inheritance\nCREATE TABLE employee (\n    id BIGSERIAL PRIMARY KEY,            -- Unique identifier with auto-increment (BIGSERIAL)\n    name VARCHAR(100) NOT NULL,          -- Common attribute for all employees\n    salary DOUBLE PRECISION,             -- Specific to FullTimeEmployee\n    hourly_rate DOUBLE PRECISION,        -- Specific to PartTimeEmployee\n    employee_type VARCHAR(20) NOT NULL   -- Discriminator column (FULL_TIME, PART_TIME)\n);\n\n-- Insert FullTimeEmployee\nINSERT INTO employee (name, salary, employee_type) VALUES ('John Doe', 60000, 'FULL_TIME');\nINSERT INTO employee (name, salary, employee_type) VALUES ('Emily Carter', 75000, 'FULL_TIME');\n\n-- Insert PartTimeEmployee\nINSERT INTO employee (name, hourly_rate, employee_type) VALUES ('Jane Smith', 15, 'PART_TIME');\nINSERT INTO employee (name, hourly_rate, employee_type) VALUES ('Tom Brown', 18, 'PART_TIME');\n<\/pre>\n<h3>2.3 Define the Java Subclasses<\/h3>\n<p>Let\u2019s start with defining the base class: <code>Employee<\/code> with shared properties (<code>id<\/code> and <code>name<\/code>) for the subclasses.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\n@Entity\n@Inheritance(strategy = InheritanceType.SINGLE_TABLE)\n@DiscriminatorColumn(name = \"employee_type\", discriminatorType = DiscriminatoryType.STRING)\npublic abstract class Employee {\n\n    private Long id;\n\n    private String name;\n\n    \/\/ Constructors, Getters, and Setters\n}\n<\/pre>\n<p>Now, we will define two subclasses: <code>FullTimeEmployee<\/code> and <code>PartTimeEmployee<\/code>. Each will have its unique properties followed by the setter and getter methods. In both the below classes, <code>employee_type<\/code> is the discriminator column, which will contain <code>FULL_TIME<\/code> for full-time employees and <code>PART_TIME<\/code> for part-time employees.<\/p>\n<h4>2.3.1 FullTimeEmployee Model class<\/h4>\n<pre class=\"brush:java; wrap-lines:false;\">\n@Entity\n@DiscriminatorValue(\"FULL_TIME\")\npublic class FullTimeEmployee extends Employee {\n    private double salary;\n\n    \/\/ Constructors, Getters, and Setters\n}\n<\/pre>\n<p>The given code defines a subclass of <code>Employee<\/code> called <code>FullTimeEmployee<\/code>, which is an entity in a Java Persistence API (JPA) context. <\/p>\n<ul>\n<li><code>@DiscriminatorValue(\"FULL_TIME\")<\/code>: This annotation is used in conjunction with single table inheritance. It specifies the value that will be stored in the discriminator column of the table to distinguish between different types of employees. In this case, the discriminator value &#8220;FULL_TIME&#8221; will be used to identify instances of <code>FullTimeEmployee<\/code> in the database table.<\/li>\n<\/ul>\n<h4>2.3.2 PartTimeEmployee Model class<\/h4>\n<pre class=\"brush:java; wrap-lines:false;\">\n@Entity\n@DiscriminatorValue(\"PART_TIME\")\npublic class PartTimeEmployee extends Employee {\n    private double hourlyRate;\n\n    \/\/ Constructors, Getters, and Setters\n}\n<\/pre>\n<p>The provided code defines a subclass of <code>Employee<\/code> called <code>PartTimeEmployee<\/code>, which is a JPA entity.<\/p>\n<ul>\n<li><code>@DiscriminatorValue(\"PART_TIME\")<\/code>: This annotation is used when implementing Single Table Inheritance in JPA. It specifies that the value &#8220;PART_TIME&#8221; will be stored in the discriminator column of the database table for rows representing <code>PartTimeEmployee<\/code> instances. This allows the system to distinguish between different types of employees, such as full-time or part-time, stored in the same table. <\/li>\n<\/ul>\n<h3>2.4 Querying with JPA Repository<\/h4>\n<p>Spring Data JPA allows us to query entities using the repository pattern. We will create a repository interface for <code>Employee<\/code> and then demonstrate how to query for specific subtypes.<\/p>\n<h4>2.4.1 Define the EmployeeRepository<\/h4>\n<p>Create an interface <code>EmployeeRepository<\/code> extending <code>JpaRepository<\/code> to provide CRUD (Create, Read, Update, and Delete) operations.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport org.springframework.data.jpa.repository.JpaRepository;\nimport java.util.List;\n\npublic interface EmployeeRepository extends JpaRepository&lt;Employee, Long&gt; {\n    List&lt;FullTimeEmployee&gt; findBySalaryGreaterThan(double salary);\n    List&lt;PartTimeEmployee&gt; findByHourlyRateLessThan(double hourlyRate);\n}\n<\/pre>\n<h4>2.4.2 Testing Queries in Service Layer<\/h4>\n<p>We will add a service class, <code>EmployeeService<\/code>, to handle the querying logic for each subtype. Here, we can inject <code>EmployeeRepository<\/code> and use the specific queries based on the subclass.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\nimport java.util.List;\n\n@Service\npublic class EmployeeService {\n    @Autowired\n    private EmployeeRepository employeeRepository;\n\n    public List&lt;FullTimeEmployee&gt; getHighSalaryEmployees(double salary) {\n        return employeeRepository.findBySalaryGreaterThan(salary);\n    }\n\n    public List&lt;PartTimeEmployee&gt; getLowHourlyRateEmployees(double hourlyRate) {\n        return employeeRepository.findByHourlyRateLessThan(hourlyRate);\n    }\n}\n<\/pre>\n<h4>2.4.3 Controller Layer to Test API Endpoints<\/h4>\n<p>Now, we\u2019ll add a controller to expose REST endpoints for these queries.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.*;\nimport java.util.List;\n\n@RestController\n@RequestMapping(\"\/employees\")\npublic class EmployeeController {\n\n    @Autowired\n    private EmployeeService employeeService;\n\n    @GetMapping(\"\/full-time\/high-salary\")\n    public List&lt;FullTimeEmployee&gt; getHighSalaryEmployees(@RequestParam double salary) {\n        return employeeService.getHighSalaryEmployees(salary);\n    }\n\n    @GetMapping(\"\/part-time\/low-hourly-rate\")\n    public List&lt;PartTimeEmployee&gt; getLowHourlyRateEmployees(@RequestParam double hourlyRate) {\n        return employeeService.getLowHourlyRateEmployees(hourlyRate);\n    }\n}\n<\/pre>\n<h3>2.5 Setting up the application properties<\/h3>\n<p>Add the following code to the application.properties file.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\nspring.datasource.url=jdbc:postgresql:\/\/localhost:5432\/test\nspring.datasource.username=your_username\nspring.datasource.password=your_password\n\nspring.jpa.hibernate.ddl-auto=update\nspring.jpa.show-sql=true\nspring.datasource.driver-class-name=org.postgresql.Driver\nspring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect\n<\/pre>\n<h3>2.6 Create a Main class<\/h3>\n<p>Add the following code to the main class that act as the entry point to the Spring boot application.<\/p>\n<pre class=\"brush:java; wrap-lines:false;\">\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n \n@SpringBootApplication\npublic class EmployeeApplication {\n\n    public static void main(String[] args) {\n        SpringApplication.run(EmployeeApplication.class, args);\n    } \n}\n<\/pre>\n<h2><a name=\"section-3\"><\/a>3. Run the application<\/h2>\n<p>Run the code by running the <code>EmployeeApplication.java<\/code> and trigger the api endpoints.<\/p>\n<pre class=\"brush:plain; wrap-lines:false;\">\n-- GET \/employees\/full-time\/high-salary?salary=50000\n[\n    {\n        \"id\": 1,\n        \"name\": \"John Doe\",\n        \"salary\": 60000.0,\n        \"employee_type\": \"FULL_TIME\"\n    },\n    ...\n]\n\n-- GET \/employees\/part-time\/low-hourly-rate?hourlyRate=20\n[\n    {\n        \"id\": 2,\n        \"name\": \"Jane Smith\",\n        \"hourlyRate\": 15.0,\n        \"employee_type\": \"PART_TIME\"\n    },\n    ...\n]\n<\/pre>\n<h2><a name=\"section-4\"><\/a>4. Conclusion<\/h2>\n<p>Using Single Table Inheritance in JPA can simplify the database structure by storing different entity types in a single table. With Spring Data JPA, querying by specific subtypes is straightforward. This approach is efficient for handling entities with shared attributes and enables easier database management. However, when there are a lot of subtype-specific fields, other inheritance strategies might be better suited. This example provides a complete overview of implementing and querying Single Table Inheritance with JPA in a Spring Boot application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Java Persistence API (JPA), inheritance mapping provides a way to map Java class hierarchies to database tables. Single Table Inheritance is one of the inheritance strategies where all entities in a class hierarchy are stored in a single database table. Although simple to implement, it requires a discriminator column to distinguish between various subclasses. &hellip;<\/p>\n","protected":false},"author":26931,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[33,30],"class_list":["post-128429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jpa","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Query JPA Single Table Inheritance - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Jpa inheritance single table: Learn how to query JPA repository with single table inheritance and subtypes in Spring Boot.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Query JPA Single Table Inheritance - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Jpa inheritance single table: Learn how to query JPA repository with single table inheritance and subtypes in Spring Boot.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-21T08:37:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin Batra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin Batra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html\"},\"author\":{\"name\":\"Yatin Batra\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\"},\"headline\":\"Query JPA Single Table Inheritance\",\"datePublished\":\"2024-11-21T08:37:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html\"},\"wordCount\":640,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"JPA\",\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html\",\"name\":\"Query JPA Single Table Inheritance - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2024-11-21T08:37:00+00:00\",\"description\":\"Jpa inheritance single table: Learn how to query JPA repository with single table inheritance and subtypes in Spring Boot.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/query-jpa-single-table-inheritance.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Query JPA Single Table Inheritance\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/cda31a4c1965373fed40c8907dc09b8d\",\"name\":\"Yatin Batra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/12\\\/Yatin.batra_.jpg\",\"caption\":\"Yatin Batra\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\\\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/yatin-batra\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Query JPA Single Table Inheritance - Java Code Geeks","description":"Jpa inheritance single table: Learn how to query JPA repository with single table inheritance and subtypes in Spring Boot.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html","og_locale":"en_US","og_type":"article","og_title":"Query JPA Single Table Inheritance - Java Code Geeks","og_description":"Jpa inheritance single table: Learn how to query JPA repository with single table inheritance and subtypes in Spring Boot.","og_url":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2024-11-21T08:37:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Yatin Batra","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin Batra","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html"},"author":{"name":"Yatin Batra","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d"},"headline":"Query JPA Single Table Inheritance","datePublished":"2024-11-21T08:37:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html"},"wordCount":640,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["JPA","Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html","url":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html","name":"Query JPA Single Table Inheritance - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2024-11-21T08:37:00+00:00","description":"Jpa inheritance single table: Learn how to query JPA repository with single table inheritance and subtypes in Spring Boot.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/query-jpa-single-table-inheritance.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Query JPA Single Table Inheritance"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/cda31a4c1965373fed40c8907dc09b8d","name":"Yatin Batra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/12\/Yatin.batra_.jpg","caption":"Yatin Batra"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/yatin-batra"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/128429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/26931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=128429"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/128429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=128429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=128429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=128429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}