Skip to content

Commit 81a0b74

Browse files
authored
chore: Add @MappedSuperclass support documentation to README (#70)
- Added feature to the features list - Created dedicated section explaining @MappedSuperclass support - Included code example showing BaseEntity inheritance pattern - Listed benefits and use cases for the feature
1 parent 02dc185 commit 81a0b74

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ all correct and functional.
2424
- Database-specific optimizations for MySQL and PostgreSQL
2525
- Automatic handling of generated keys
2626
- Batch operation support for improved performance
27+
- Support for @MappedSuperclass inheritance
2728

2829
## What is Upsert?
2930

@@ -176,6 +177,47 @@ This is particularly useful for:
176177
- **Price protection**: Prevent accidental price increases
177178
- **Concurrent update protection**: Avoid overwriting newer data with older data
178179

180+
### @MappedSuperclass Support
181+
182+
Since version 1.5.0, the library fully supports entities that inherit fields from classes annotated with `@MappedSuperclass`. This allows you to define common fields in a base class and have them properly recognized during upsert operations.
183+
184+
```kotlin
185+
@MappedSuperclass
186+
abstract class BaseEntity(
187+
@Column(name = "created_at")
188+
open val createdAt: LocalDateTime = LocalDateTime.now(),
189+
190+
@Column(name = "updated_at")
191+
open val updatedAt: LocalDateTime = LocalDateTime.now(),
192+
193+
@Column(name = "version")
194+
open val version: Int = 1
195+
)
196+
197+
@Entity
198+
@Table(name = "users", uniqueConstraints = [UniqueConstraint(columnNames = ["username"])])
199+
class User(
200+
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
201+
val id: Long? = null,
202+
203+
@Column(unique = true)
204+
val username: String,
205+
206+
val email: String,
207+
208+
// Inherited fields from BaseEntity
209+
createdAt: LocalDateTime = LocalDateTime.now(),
210+
updatedAt: LocalDateTime = LocalDateTime.now(),
211+
version: Int = 1
212+
) : BaseEntity(createdAt, updatedAt, version)
213+
```
214+
215+
The library automatically discovers fields from parent classes annotated with `@MappedSuperclass`, allowing you to:
216+
- Define common audit fields (createdAt, updatedAt) in a base class
217+
- Implement versioning for optimistic locking
218+
- Share common fields across multiple entities
219+
- Use all upsert features with inherited fields
220+
179221
## Configuration
180222

181223
The library is automatically configured when you include it in your Spring Boot application. No

0 commit comments

Comments
 (0)