mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-06 02:23:19 +00:00
docs: Content SEO updates (#2990)
* update yaml frontmatter format * update abstract document * update abstract factory * use the new pattern template * acyclic visitor seo * adapter seo * ambassador seo * acl seo * aaa seo * async method invocation seo * balking seo * bridge seo * builder seo * business delegate and bytecode seo * caching seo * callback seo * chain seo * update headings * circuit breaker seo * client session + collecting parameter seo * collection pipeline seo * combinator SEO * command seo * cqrs seo * commander seo * component seo * composite seo * composite entity seo * composite view seo * context object seo * converter seo * crtp seo * currying seo * dao seo * data bus seo * data locality seo * data mapper seo * dto seo * decorator seo * delegation seo * di seo * dirty flag seo * domain model seo * double buffer seo * double checked locking seo * double dispatch seo * dynamic proxy seo * event aggregator seo * event-based asynchronous seo * eda seo * event queue seo * event sourcing seo * execute around seo * extension objects seo * facade seo * factory seo * factory kit seo * factory method seo * fanout/fanin seo * feature toggle seo * filterer seo * fluent interface seo * flux seo * flyweight seo * front controller seo * function composition seo * game loop seo * gateway seo * guarded suspension seo * half-sync/half-async seo * health check seo * hexagonal seo * identity map seo * intercepting filter seo * interpreter seo * iterator seo * layers seo * lazy loading seo * leader election seo * leader/followers seo * lockable object seo * rename and add seo for marker interface * master-worker seo * mediator seo * memento seo * metadata mapping seo * microservice aggregator seo * api gw seo * microservices log aggregration seo * mvc seo * mvi seo * mvp seo * mvvm seo * monad seo * monitor seo * monostate seo * multiton seo * mute idiom seo * naked objects & notification seo * null object seo * object mother seo * object pool seo * observer seo * optimistic locking seo * page controller seo * page object seo * parameter object seo * partial response seo * pipeline seo * poison pill seo * presentation model seo * private class data seo * producer-consumer seo * promise seo * property seo * prototype seo * proxy seo * queue-based load leveling seo * reactor seo * registry seo * repository seo * RAII seo * retry seo * role object seo * saga seo * separated interface seo * serialized entity seo * serialized lob seo * servant seo * server session seo * service layer seo * service locator seo * service to worker seo * sharding seo * single table inheritance seo * singleton seo * spatial partition seo * special case seo * specification seo * state seo * step builder seo * strangler seo * strategy seo * subclass sandbox seo * table module seo * template method seo * throttling seo * tolerant reader seo * trampoline seo * transaction script seo * twin seo * type object seo * unit of work seo * update method seo * value object seo * version number seo * virtual proxy seo * visitor seo * seo enhancements * seo improvements * SEO enhancements * SEO improvements * SEO additions * SEO improvements * more SEO improvements * rename hexagonal + SEO improvements * SEO improvements * more SEO stuff * SEO improvements * SEO optimizations * SEO enhancements * enchance SEO * improve SEO * SEO improvements * update headers
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
---
|
||||
title: Single Table Inheritance
|
||||
title: "Single Table Inheritance Pattern in Java: Streamlining Object Mapping with Unified Table Structures"
|
||||
shortTitle: Single Table Inheritance
|
||||
description: "Discover how the Single Table Inheritance pattern simplifies database schema in Java applications. Learn its use, benefits, and implementation in our comprehensive guide."
|
||||
category: Data access
|
||||
language: en
|
||||
tag:
|
||||
- Data access
|
||||
- Encapsulation
|
||||
- Persistence
|
||||
- Polymorphism
|
||||
- Data access
|
||||
- Encapsulation
|
||||
- Persistence
|
||||
- Polymorphism
|
||||
---
|
||||
|
||||
## Also known as
|
||||
@@ -14,11 +16,13 @@ tag:
|
||||
* Class Table Inheritance
|
||||
* STI
|
||||
|
||||
## Intent
|
||||
## Intent of Single Table Inheritance Design Pattern
|
||||
|
||||
Simplify the storage of an inheritance hierarchy in a single database table, where rows represent objects of different classes and columns represent the union of all attributes.
|
||||
Single Table Inheritance pattern simplifies database schema in Java applications.
|
||||
|
||||
## Explanation
|
||||
Streamline the storage of an inheritance hierarchy in a single database table, where rows represent objects of different classes and columns represent the union of all attributes.
|
||||
|
||||
## Detailed Explanation of Single Table Inheritance Pattern with Real-World Examples
|
||||
|
||||
Real-world example
|
||||
|
||||
@@ -32,7 +36,7 @@ Wikipedia says
|
||||
|
||||
> Single table inheritance is a way to emulate object-oriented inheritance in a relational database. When mapping from a database table to an object in an object-oriented language, a field in the database identifies what class in the hierarchy the object belongs to. All fields of all the classes are stored in the same table, hence the name "Single Table Inheritance".
|
||||
|
||||
**Programmatic Example**
|
||||
## Programmatic Example of Single Table Inheritance Pattern in Java
|
||||
|
||||
Single Table Inheritance is a design pattern that maps an inheritance hierarchy of classes to a single database table. Each row in the table represents an instance of a class in the hierarchy. A special discriminator column is used to identify the class to which each row belongs.
|
||||
|
||||
@@ -215,24 +219,26 @@ Console output:
|
||||
|
||||
The Single Table Inheritance pattern is a simple and efficient way to map an inheritance hierarchy to a relational database. However, it can lead to sparse tables if subclasses have many unique fields. In such cases, other patterns like Class Table Inheritance or Concrete Table Inheritance might be more appropriate.
|
||||
|
||||
## Applicability
|
||||
## When to Use the Single Table Inheritance Pattern in Java
|
||||
|
||||
* Use when you have a class hierarchy with subclasses that share a common base class and you want to store all instances of the hierarchy in a single table.
|
||||
* Ideal for small to medium-sized applications where the simplicity of a single table outweighs the performance cost of null fields for some subclasses.
|
||||
|
||||
### Tutorials
|
||||
## Single Table Inheritance Pattern Tutorials
|
||||
|
||||
* [Hibernate Tutorial 18 - Implementing Inheritance - Single Table Strategy (Java Brains)](https://www.youtube.com/watch?v=M5YrLtAHtOo)
|
||||
|
||||
## Known uses
|
||||
## Real-World Applications of Single Table Inheritance Pattern in Java
|
||||
|
||||
* Hibernate and JPA implementations in Java applications often use Single Table Inheritance for ORM mapping.
|
||||
* Rails ActiveRecord supports Single Table Inheritance out of the box.
|
||||
|
||||
## Consequences
|
||||
## Benefits and Trade-offs of Single Table Inheritance Pattern
|
||||
|
||||
Benefits:
|
||||
|
||||
Using the Single Table Inheritance pattern in Java ORM
|
||||
|
||||
* Simplifies database schema by reducing the number of tables.
|
||||
* Easier to manage relationships and queries since all data is in one table.
|
||||
|
||||
@@ -242,12 +248,12 @@ Trade-offs:
|
||||
* May cause performance issues for large hierarchies due to table size and the need to filter by type.
|
||||
* Changes in the inheritance hierarchy require schema changes.
|
||||
|
||||
## Related patterns
|
||||
## Related Java Design Patterns
|
||||
|
||||
* Class Table Inheritance: Uses separate tables for each class in the hierarchy, reducing null values but increasing complexity in joins.
|
||||
* Concrete Table Inheritance: Each class in the hierarchy has its own table, reducing redundancy but increasing the number of tables.
|
||||
|
||||
## Credits
|
||||
## References and Credits
|
||||
|
||||
* [Domain-Driven Design: Tackling Complexity in the Heart of Software](https://amzn.to/3wlDrze)
|
||||
* [Java Persistence with Hibernate](https://amzn.to/44tP1ox)
|
||||
|
||||
Reference in New Issue
Block a user