Agent skill · Audited from source
kotlin-backend-jpa-entity-mapping
skill · kotlin/kotlin-agent-skillsApache-2.0 licenceAudited 20 Oct 2026 · source 25b8117b6cd6
Is it safe? Yes — SAFE, grade B (89/100). We read this skill's source at commit 25b8117b6cd6 and found no filesystem, network or shell access and no hard-coded secrets. What it does: Model Kotlin persistence code correctly for Spring Data JPA and Hibernate. Covers entity design, identity and equality, uniqueness constraints, relationships, fetch plans, and common ORM (Object-Relational Mapping)…
Cite
Cite this page
ModelsAtlas. “kotlin-backend-jpa-entity-mapping (kotlin/kotlin-agent-skills)”. Retrieved 20 Oct 2026. https://modelsatlas.com/skills/kotlin/kotlin-backend-jpa-entity-mapping
Trust audit
Audit 0.4.1 · source read 20 Oct 2026
SAFE means nothing in the source contradicts what the skill says it does. Grade B is shared by 13,985 of 14,816 audited skills.
What the source does
- FilesystemNone observedNo reads or writes in the source
- NetworkNone observedNo outbound calls in the source
- ShellNone observedNo commands run in the source
- DependenciesPinnedNothing floats
- SecretsNone foundNo keys in source
Five audit layers
| Layer | What we check | Result | Findings |
|---|---|---|---|
L0 Provenance | Repo owner, licence, archive status, activity | WARN | 1 |
L1 Static source | Secrets, path traversal, supply chain, hidden code | NA | 0 |
L2 Instructions | Prompt injection, authority framing, hidden directives | PASS | 0 |
L3 Inventory | The files and declarations match the source | PASS | 0 |
L4 Sandbox | Run in isolation and watch behaviour | SKIPPED why | 0 |
Gates applied: no behavioural pass.
Findings (1)
MEDIUMInventory / provenanceinv.symlink · plugins/kotlin-agent-skills/skills
plugins/kotlin-agent-skills/skills
- Why
- link not followed
- Fix
- —
Audit 0.4.1 · source sha 25b8117b6cd6 · 20 Oct 2026Report an issue or request a re-scan
Provenance
Who published it, and what the verdict is pinned to
- Publisherkotlin GitHub organizationOwner of the repository this skill is read from
- Source folderkotlin/kotlin-agent-skills/skills/kotlin-backend-jpa-entity-mappingThe exact folder we audited
- LicenceApache-2.0As the repository states it
- Commit pinned for this verdict25b8117b6cd6A new audit runs when the source changes
- Repository statusNot archivedLast push 12 days ago
- Sandboxed runNot runSkills are read, not executed; layer L4 is skipped
What it tells the agent
Full source on GitHub ↗Its description: Model Kotlin persistence code correctly for Spring Data JPA and Hibernate. Covers entity design, identity and equality, uniqueness constraints, relationships, fetch plans, and common ORM (Object-Relational Mapping)…
---
name: kotlin-backend-jpa-entity-mapping
description: >
Model Kotlin persistence code correctly for Spring Data JPA and Hibernate.
Covers entity design, identity and equality, uniqueness constraints,
relationships, fetch plans, and common ORM (Object-Relational Mapping) traps
specific to Kotlin. Use when creating or reviewing JPA (Java Persistence API)
entities, diagnosing N+1 or LazyInitializationException, placing indexes and
uniqueness rules, or preventing Kotlin-specific bugs such as data class
entities and broken equals/hashCode.
license: Apache-2.0
metadata:
author: JetBrains
version: "1.0.0"
---
# JPA Entity Mapping for Kotlin
Kotlin's `data class` is natural for DTOs but dangerous for JPA entities. Hibernate relies on
identity semantics that `data class` breaks: `equals`/`hashCode` over all fields corrupts
`Set`/`Map` membership after state changes, and auto-generated `copy()` creates detached
duplicates of managed entities.
This skill teaches correct entity design, identity strategies, and uniqueness constraints
for Kotlin + Spring Data JPA projects.
## Entity Design Rules
- **Never use `data class` for JPA entities.** Use a regular `class`. Keep `data class` for DTOs.
- Keep transport DTOs and persistence entities separate unless the project clearly uses a shared model.
- Model required columns as non-null only when object construction and persistence lifecycle make it safe.
- Use `lateinit` only when the project already accepts that tradeoff and the lifecycle is safe.
- Verify `kotlin("plugin.jpa")` or equivalent no-arg support when JPA entities exist.
- Verify classes and members are compatible with proxying where needed.
## Identity and Equality
- Never accept all-field `equals`/`hashCode` generated by `data class` on an entity.
- Follow project conventions when they already define an identity strategy.
- If no convention exists, use ID-based equality with a stable `hashCode`.
- For DB-generated IDs, model the unsaved state with nullable `var id: Long? = null`
and a `protected set`; do not use `0L` as a sentinel value.
- Be explicit about mutable fields and lazy associations when discussing equality.
### Broken: `data class` Entity
```kotlin
// WRONG: data class generates equals/hashCode from ALL fields,
// and the generated ID uses a 0 sentinel instead of null
data class Order(
@Id @GeneratedValue val id: Long = 0,
var status: String,
var total: BigDecimal
)
// BUG: order.status = "SHIPPED"; set.contains(order) → false (hash changed)
// BUG: Hibernate proxy.equals(entity) → false (proxy has lazy fields uninitialized)
```
### Correct: Regular Class with ID-Based Identity
```kotlin
@Entity
@Table(name = "orders")
class Order(
@Column(nullable = false)
var status: String,
@Column(nullable = false)
var total: BigDecimal
) {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null
protected set
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Order) return false
return id != null && id == other.id
}
override fun hashCode(): Int = javaClass.hashCode()
// toString must NOT reference lazy collections
override fun toString(): String = "Order(id=$id, status=$status)"
}
```
**Key rules:**
- `equals` compares by ID only — stable under dirty tracking and proxy unwrapping
- `hashCode` returns class-based constant — avoids `Set`/`Map` corruption after persist
- `toString` excludes lazy-loaded relations — prevents `LazyInitializationException`
- Constructor params are mutable entity fields; DB-generated `id` is nullable with a protected setter
## Uniqueness Constraints
When an API must be idempotent (e.g., "reserve stock for order X"), enforce uniqueness
at both layers: database constraint for correctness, application check for clean errors.
### Broken: No Duplicate Guard
```kotlin
@Service
class ReservationService(private val repo: ReservationRepository) {
@Transactional
fun createReservation(variantId: Long, orderId: String, qty: Int): Reservation {
// BUG: no check — duplicates silently accumulate
return repo.save(Reservation(variantId = variantId, orderId = orderId, quantity = qty))
}
}
```
### Correct: Database Constraint + Application Guard
```kotlin
@Entity
@Table(
name = "reservations",
uniqueConstraints = [
UniqueConstraint(columnNames = ["variant_id", "order_id"])
]
)
class Reservation(
@Column(name = "variant_id", nullable = false)
val variantId: Long,
@Column(name = "order_id", nullable = false)
val orderId: String,
@Column(nullable = false)
var quantity: Int
) {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null
protected set
}
interface ReservationRepository : JpaRepository<Reservation, Long> {
fun findByVariantIdAndOrderId(variantId: Long, orderId: String): Reservation?
}
@Service
class ReservationService(private val repo: ReservationRepository) {
@Transactional
fun createReservation(variantId: Long, orderId: String, qty: Int): Reservation {
repo.findByVariantIdAndOrderId(variantId, orderId)?.let {
throw IllegalStateException(
"Reservation already exists for variant=$variantId, order=$orderId"
)
}
return repo.save(Reservation(variantId = variantId, orderId = orderId, quantity = qty))
}
}
```
**Key rules:**
- Database constraint is mandatory — application checks alone have race conditions
- Application check provides clean error messages — without it, users get raw `DataIntegrityViolationException`
- Both layers together: application catches the common case, database catches the race
- Spring Data derives `findByXAndY` queries automatically
## Query and Fetch Rules
- Diagnose N+1 by looking at actual query count or SQL logs, not by guessing from annotations.
- Prefer targeted fetcExcerpt, first 6,000 characters of SKILL.md, verbatim from the audited commit. It is text from someone else’s repository, quoted so you can judge it before your agent reads it.
Install
Pinned to the audited commit 25b8117
git clone https://github.com/kotlin/kotlin-agent-skills git -C kotlin-agent-skills checkout 25b8117b6cd6
The author documents no install command, so this uses the repository directly. Our verdict covers commit 25b8117b6cd6 only.
Works in
The author has not said which agents this skill supports, and we have not tested it in any.
Audit history
Every audit, every source change
- ✓SAFE B 89 / 100
first audit · source
25b8117b6cd6
README badge
For maintainers · shows the latest audit
[](https://modelsatlas.com/skills/kotlin/kotlin-backend-jpa-entity-mapping/)
The badge shows our verdict and grade for this skill, and links back to this page. It changes when the audit does.
Similar skills
All coding & review skills →chrisbanes/skills
Use when writing or reviewing Jetpack Compose motion: visibility enter/exit, animating one property toward a target, color or size transitions, multiple properties from one state, switching composable content, or…
chrisbanes/skills
Use when writing or reviewing Jetpack Compose UI for TV, keyboard, desktop, accessibility focus, D-pad navigation, FocusRequester, focusProperties, key events, or initial focus behavior.
chrisbanes/skills
Skills for Kotlin, Jetpack Compose, and Android development
chrisbanes/skills
Skills for Kotlin, Jetpack Compose, and Android development
chrisbanes/skills
Skills for Kotlin, Jetpack Compose, and Android development
chrisbanes/skills
Skills for Kotlin, Jetpack Compose, and Android development
Add this badge to your README
[](https://modelsatlas.com/skills/kotlin/kotlin-backend-jpa-entity-mapping/)
<a href="https://modelsatlas.com/skills/kotlin/kotlin-backend-jpa-entity-mapping/"><img src="https://modelsatlas.com/skills/kotlin/kotlin-backend-jpa-entity-mapping/badge.svg" alt="ModelsAtlas: SAFE B"></a>
Questions about kotlin-backend-jpa-entity-mapping
What does the kotlin-backend-jpa-entity-mapping skill do?
Is kotlin-backend-jpa-entity-mapping safe to install?
What can kotlin-backend-jpa-entity-mapping access on my machine?
How current is this page?
Sources
- github.com/kotlin/kotlin-agent-skills/tree/main/skills/kotlin-ba — the audited source at commit 25b8117b6cd6 and every finding aboveObserved · 20 Oct 2026
Spotted something wrong? Report a correction · Methodology
Keep going in your AI
Opens with this page as the source. We add nothing else to the prompt.
- What does the kotlin-backend-jpa-entity-mapping skill do?
- Is kotlin-backend-jpa-entity-mapping safe to install?
- What can kotlin-backend-jpa-entity-mapping access on my machine?