[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71D6NCAV7T754QC6HHYPV3F":3,"skill-same:01M71D6NCAV7T754QC6HHYPV3F":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":35,"linkOnly":36,"markdownContent":37,"markdownBody":38,"frontMatter":39,"refName":40,"commitSha":41,"skillDirectory":42,"forksCount":14,"repositoryHtmlUrl":43,"repositoryHomepageUrl":6,"ownerHtmlUrl":44,"ownerBlogUrl":6,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M71D6NCAV7T754QC6HHYPV3F","devel-jb-kotlin-backend-jpa-entity-mapping",null,"- Do not claim an N+1 fix without explaining how the fetch plan changes query behavior.","DCx7C5\u002Fai-marketplace","DCx7C5","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F42419559?v=4","01M71C01G2AZV3NTNGWAWSHJPP","DC","01M71C01GQW6G50S2BYMS7PP3E",0,"MIT","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-kotlin-backend-jpa-entity-mapping\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34],"kotlin","backend","devel jb kotlin backend jpa entity mapping","mapping","jpa","entity","do","fetch","fix","claim","cybersecurity","query","plan","changes","how","behavior","2026-11-10 10:12:30",false,"---\nname: devel-jb-kotlin-backend-jpa-entity-mapping\ndescription: \"- Do not claim an N+1 fix without explaining how the fetch plan changes query behavior.\"\ndomain: cybersecurity\n---\n\n# JPA Entity Mapping for Kotlin\n\nKotlin's `data class` is natural for DTOs but dangerous for JPA entities. Hibernate relies on\nidentity semantics that `data class` breaks: `equals`\u002F`hashCode` over all fields corrupts\n`Set`\u002F`Map` membership after state changes, and auto-generated `copy()` creates detached\nduplicates of managed entities.\n\nThis skill teaches correct entity design, identity strategies, and uniqueness constraints\nfor Kotlin + Spring Data JPA projects.\n\n## Entity Design Rules\n\n- **Never use `data class` for JPA entities.** Use a regular `class`. Keep `data class` for DTOs.\n- Keep transport DTOs and persistence entities separate unless the project clearly uses a shared model.\n- Model required columns as non-null only when object construction and persistence lifecycle make it safe.\n- Use `lateinit` only when the project already accepts that tradeoff and the lifecycle is safe.\n- Verify `kotlin(\"plugin.jpa\")` or equivalent no-arg support when JPA entities exist.\n- Verify classes and members are compatible with proxying where needed.\n\n## Identity and Equality\n\n- Never accept all-field `equals`\u002F`hashCode` generated by `data class` on an entity.\n- Follow project conventions when they already define an identity strategy.\n- If no convention exists, use ID-based equality with a stable `hashCode`.\n- Be explicit about mutable fields and lazy associations when discussing equality.\n\n### Broken: `data class` Entity\n\n```kotlin\n\u002F\u002F WRONG: data class generates equals\u002FhashCode from ALL fields\ndata class Order(\n    @Id @GeneratedValue val id: Long = 0,\n    var status: String,\n    var total: BigDecimal\n)\n\u002F\u002F BUG: order.status = \"SHIPPED\"; set.contains(order) → false (hash changed)\n\u002F\u002F BUG: Hibernate proxy.equals(entity) → false (proxy has lazy fields uninitialized)\n```\n\n### Correct: Regular Class with ID-Based Identity\n\n```kotlin\n@Entity\n@Table(name = \"orders\")\nclass Order(\n    @Column(nullable = false)\n    var status: String,\n\n    @Column(nullable = false)\n    var total: BigDecimal\n) {\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    val id: Long = 0\n\n    override fun equals(other: Any?): Boolean {\n        if (this === other) return true\n        if (other !is Order) return false\n        return id != 0L && id == other.id\n    }\n\n    override fun hashCode(): Int = javaClass.hashCode()\n\n    \u002F\u002F toString must NOT reference lazy collections\n    override fun toString(): String = \"Order(id=$id, status=$status)\"\n}\n```\n\n**Key rules:**\n- `equals` compares by ID only — stable under dirty tracking and proxy unwrapping\n- `hashCode` returns class-based constant — avoids `Set`\u002F`Map` corruption after persist\n- `toString` excludes lazy-loaded relations — prevents `LazyInitializationException`\n- Constructor params are mutable entity fields; `id` is `val` with default\n\n## Uniqueness Constraints\n\nWhen an API must be idempotent (e.g., \"reserve stock for order X\"), enforce uniqueness\nat both layers: database constraint for correctness, application check for clean errors.\n\n### Broken: No Duplicate Guard\n\n```kotlin\n@Service\nclass ReservationService(private val repo: ReservationRepository) {\n    @Transactional\n    fun createReservation(variantId: Long, orderId: String, qty: Int): Reservation {\n        \u002F\u002F BUG: no check — duplicates silently accumulate\n        return repo.save(Reservation(variantId = variantId, orderId = orderId, quantity = qty))\n    }\n}\n```\n\n### Correct: Database Constraint + Application Guard\n\n```kotlin\n@Entity\n@Table(\n    name = \"reservations\",\n    uniqueConstraints = [\n        UniqueConstraint(columnNames = [\"variant_id\", \"order_id\"])\n    ]\n)\nclass Reservation(\n    @Column(name = \"variant_id\", nullable = false)\n    val variantId: Long,\n\n    @Column(name = \"order_id\", nullable = false)\n    val orderId: String,\n\n    @Column(nullable = false)\n    var quantity: Int\n) {\n    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)\n    val id: Long = 0\n}\n\ninterface ReservationRepository : JpaRepository\u003CReservation, Long> {\n    fun findByVariantIdAndOrderId(variantId: Long, orderId: String): Reservation?\n}\n\n@Service\nclass ReservationService(private val repo: ReservationRepository) {\n    @Transactional\n    fun createReservation(variantId: Long, orderId: String, qty: Int): Reservation {\n        repo.findByVariantIdAndOrderId(variantId, orderId)?.let {\n            throw IllegalStateException(\n                \"Reservation already exists for variant=$variantId, order=$orderId\"\n            )\n        }\n        return repo.save(Reservation(variantId = variantId, orderId = orderId, quantity = qty))\n    }\n}\n```\n\n**Key rules:**\n- Database constraint is mandatory — application checks alone have race conditions\n- Application check provides clean error messages — without it, users get raw `DataIntegrityViolationException`\n- Both layers together: application catches the common case, database catches the race\n- Spring Data derives `findByXAndY` queries automatically\n\n## Query and Fetch Rules\n\n- Diagnose N+1 by looking at actual query count or SQL logs, not by guessing from annotations.\n- Prefer targeted fetch solutions: `@EntityGraph`, `JOIN FETCH`, batch fetching, or DTO projection.\n- Be careful with collection fetch joins plus pagination — call out the tradeoff.\n- Use indexes and uniqueness constraints to support real query patterns.\n\n## Common ORM Traps\n\n- **Bidirectional associations:** maintain both sides in domain methods. Half-updated graphs cause subtle bugs.\n- **`orphanRemoval` vs cascade remove:** not interchangeable. Explain lifecycle semantics before choosing.\n- **Lazy load triggers:** `toString`, debug logging, JSON serialization, and IDE inspection can all trigger lazy loads.\n- **Bulk updates\u002Fdeletes:** bypass persistence context and lifecycle callbacks. Subsequent reads may be stale.\n- **Multiple bag fetches:** can cause Cartesian explosion. Verify the ORM can execute collection-heavy fetch plans safely.\n- **`Set` + mutable equality:** collection membership can break after entity state changes.\n- **`@Version`:** the clearest optimistic concurrency mechanism when concurrent updates matter.\n- **`open-in-view` disabled:** DTO mapping touching lazy fields must happen inside a transaction boundary.\n\n## Guardrails\n\n- Do not use `data class` for JPA entities.\n- Do not recommend `FetchType.EAGER` everywhere to silence lazy loading symptoms.\n- Do not expose entities directly through API responses by default.\n- Do not claim an N+1 fix without explaining how the fetch plan changes query behavior.\n","# JPA Entity Mapping for Kotlin\n\nKotlin's `data class` is natural for DTOs but dangerous for JPA entities. Hibernate relies on\nidentity semantics that `data class` breaks: `equals`\u002F`hashCode` over all fields corrupts\n`Set`\u002F`Map` membership after state changes, and auto-generated `copy()` creates detached\nduplicates of managed entities.\n\nThis skill teaches correct entity design, identity strategies, and uniqueness constraints\nfor Kotlin + Spring Data JPA projects.\n\n## Entity Design Rules\n\n- **Never use `data class` for JPA entities.** Use a regular `class`. Keep `data class` for DTOs.\n- Keep transport DTOs and persistence entities separate unless the project clearly uses a shared model.\n- Model required columns as non-null only when object construction and persistence lifecycle make it safe.\n- Use `lateinit` only when the project already accepts that tradeoff and the lifecycle is safe.\n- Verify `kotlin(\"plugin.jpa\")` or equivalent no-arg support when JPA entities exist.\n- Verify classes and members are compatible with proxying where needed.\n\n## Identity and Equality\n\n- Never accept all-field `equals`\u002F`hashCode` generated by `data class` on an entity.\n- Follow project conventions when they already define an identity strategy.\n- If no convention exists, use ID-based equality with a stable `hashCode`.\n- Be explicit about mutable fields and lazy associations when discussing equality.\n\n### Broken: `data class` Entity\n\n```kotlin\n\u002F\u002F WRONG: data class generates equals\u002FhashCode from ALL fields\ndata class Order(\n    @Id @GeneratedValue val id: Long = 0,\n    var status: String,\n    var total: BigDecimal\n)\n\u002F\u002F BUG: order.status = \"SHIPPED\"; set.contains(order) → false (hash changed)\n\u002F\u002F BUG: Hibernate proxy.equals(entity) → false (proxy has lazy fields uninitialized)\n```\n\n### Correct: Regular Class with ID-Based Identity\n\n```kotlin\n@Entity\n@Table(name = \"orders\")\nclass Order(\n    @Column(nullable = false)\n    var status: String,\n\n    @Column(nullable = false)\n    var total: BigDecimal\n) {\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    val id: Long = 0\n\n    override fun equals(other: Any?): Boolean {\n        if (this === other) return true\n        if (other !is Order) return false\n        return id != 0L && id == other.id\n    }\n\n    override fun hashCode(): Int = javaClass.hashCode()\n\n    \u002F\u002F toString must NOT reference lazy collections\n    override fun toString(): String = \"Order(id=$id, status=$status)\"\n}\n```\n\n**Key rules:**\n- `equals` compares by ID only — stable under dirty tracking and proxy unwrapping\n- `hashCode` returns class-based constant — avoids `Set`\u002F`Map` corruption after persist\n- `toString` excludes lazy-loaded relations — prevents `LazyInitializationException`\n- Constructor params are mutable entity fields; `id` is `val` with default\n\n## Uniqueness Constraints\n\nWhen an API must be idempotent (e.g., \"reserve stock for order X\"), enforce uniqueness\nat both layers: database constraint for correctness, application check for clean errors.\n\n### Broken: No Duplicate Guard\n\n```kotlin\n@Service\nclass ReservationService(private val repo: ReservationRepository) {\n    @Transactional\n    fun createReservation(variantId: Long, orderId: String, qty: Int): Reservation {\n        \u002F\u002F BUG: no check — duplicates silently accumulate\n        return repo.save(Reservation(variantId = variantId, orderId = orderId, quantity = qty))\n    }\n}\n```\n\n### Correct: Database Constraint + Application Guard\n\n```kotlin\n@Entity\n@Table(\n    name = \"reservations\",\n    uniqueConstraints = [\n        UniqueConstraint(columnNames = [\"variant_id\", \"order_id\"])\n    ]\n)\nclass Reservation(\n    @Column(name = \"variant_id\", nullable = false)\n    val variantId: Long,\n\n    @Column(name = \"order_id\", nullable = false)\n    val orderId: String,\n\n    @Column(nullable = false)\n    var quantity: Int\n) {\n    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)\n    val id: Long = 0\n}\n\ninterface ReservationRepository : JpaRepository\u003CReservation, Long> {\n    fun findByVariantIdAndOrderId(variantId: Long, orderId: String): Reservation?\n}\n\n@Service\nclass ReservationService(private val repo: ReservationRepository) {\n    @Transactional\n    fun createReservation(variantId: Long, orderId: String, qty: Int): Reservation {\n        repo.findByVariantIdAndOrderId(variantId, orderId)?.let {\n            throw IllegalStateException(\n                \"Reservation already exists for variant=$variantId, order=$orderId\"\n            )\n        }\n        return repo.save(Reservation(variantId = variantId, orderId = orderId, quantity = qty))\n    }\n}\n```\n\n**Key rules:**\n- Database constraint is mandatory — application checks alone have race conditions\n- Application check provides clean error messages — without it, users get raw `DataIntegrityViolationException`\n- Both layers together: application catches the common case, database catches the race\n- Spring Data derives `findByXAndY` queries automatically\n\n## Query and Fetch Rules\n\n- Diagnose N+1 by looking at actual query count or SQL logs, not by guessing from annotations.\n- Prefer targeted fetch solutions: `@EntityGraph`, `JOIN FETCH`, batch fetching, or DTO projection.\n- Be careful with collection fetch joins plus pagination — call out the tradeoff.\n- Use indexes and uniqueness constraints to support real query patterns.\n\n## Common ORM Traps\n\n- **Bidirectional associations:** maintain both sides in domain methods. Half-updated graphs cause subtle bugs.\n- **`orphanRemoval` vs cascade remove:** not interchangeable. Explain lifecycle semantics before choosing.\n- **Lazy load triggers:** `toString`, debug logging, JSON serialization, and IDE inspection can all trigger lazy loads.\n- **Bulk updates\u002Fdeletes:** bypass persistence context and lifecycle callbacks. Subsequent reads may be stale.\n- **Multiple bag fetches:** can cause Cartesian explosion. Verify the ORM can execute collection-heavy fetch plans safely.\n- **`Set` + mutable equality:** collection membership can break after entity state changes.\n- **`@Version`:** the clearest optimistic concurrency mechanism when concurrent updates matter.\n- **`open-in-view` disabled:** DTO mapping touching lazy fields must happen inside a transaction boundary.\n\n## Guardrails\n\n- Do not use `data class` for JPA entities.\n- Do not recommend `FetchType.EAGER` everywhere to silence lazy loading symptoms.\n- Do not expose entities directly through API responses by default.\n- Do not claim an N+1 fix without explaining how the fetch plan changes query behavior.\n",{"name":5,"domain":29,"description":7},"main","a91f1293287ffa9f4f1b8f486cd6e835a1568c84","skills\u002Fdevel-jb-kotlin-backend-jpa-entity-mapping","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace","https:\u002F\u002Fgithub.com\u002FDCx7C5","#Python","2026-09-01 11:21:00",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add DCx7C5\u002Fai-marketplace --skill devel-jb-kotlin-backend-jpa-entity-mapping",{"tool":53,"command":54},"bunx","bunx skills add DCx7C5\u002Fai-marketplace --skill devel-jb-kotlin-backend-jpa-entity-mapping",{"tool":56,"command":57},"pnpm","pnpm dlx skills add DCx7C5\u002Fai-marketplace --skill devel-jb-kotlin-backend-jpa-entity-mapping","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-kotlin-backend-jpa-entity-mapping\u002FSKILL.md",true,[61],{"path":62,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":66},"index.json","REFERENCE","参考文档",612,"https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-kotlin-backend-jpa-entity-mapping\u002Findex.json",[68,78,103,126,148,170],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":72,"licenseFileUrl":73,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":77},"01M73MDK3NT5XHNYTQ5P5172V9","devel-jb-algorithmic-art","- Embed algorithms inline in the HTML artifact (don't create separate .","Apache-2.0","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-algorithmic-art\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fdevel-jb-algorithmic-art\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":35},"01M71HAPZ01KQ30RKTB0FFSQ05","services-wmi-persistence-detect","Detect WMI event subscription persistence by enumerating ActiveScriptEventConsumer, CommandLineEventConsumer, and permanent subscriptions in the WMI repository.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fservices\u002Fwmi\u002Fpersistence\u002Fdetect\u002FSKILL.md",[],[85,86,87,88,89,90,91,29,92,93,94,95,96,97,98,99,100,101,102],"services","detect","services wmi persistence detect","wmi","persistence","process-forensics","process","forensics","t1546.003","event-subscription","subscription","repository","commandline-consumer","subscriptions","event","activescript","cm","de",{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":35},"01M71HAK6JTTTS229T17WJMMCG","services-wmi-exec-exploit","Perform lateral movement across Windows networks using WMI-based remote execution techniques including Impacket wmiexec.py, CrackMapExec, and native WMI commands for stealthy post-exploitation during red team engagements.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fservices\u002Fwmi\u002Fexec\u002Fexploit\u002FSKILL.md",[],[110,88,111,85,112,113,114,115,116,29,117,118,119,120,121,122,123,124,102,125],"exec","services wmi exec exploit","exploit","across","Bash","analysis","team","traffic","remote","crackmapexec","Impacket","lateral-movement","read","lateral movement","command","native",{"skillNo":127,"name":128,"nameZh":6,"description":129,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":35},"01M71HAG6MHKNQV8KDZKMT4886","registry-artifact-extract","Extract and analyze Windows Registry hives to uncover user activity, installed software, autostart entries, and evidence of system compromise.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fregistry\u002Fartifact\u002Fextract\u002FSKILL.md",[],[133,134,135,136,137,138,139,140,141,142,122,102,143,144,115,145,114,29,146,147],"extract","registry artifact extract","registry","artifact","digital-forensics","sonnet","regripper","windows-registry","evidence-collection","software","uncover","analyze","collection","artifact-analysis","activity",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":35},"01M71HACR4A8XTWTTSXK4124AA","processes-token-impersonate-detect","Detect Windows token impersonation and privilege abuse including SeImpersonatePrivilege exploitation via Potato attacks and token stealing techniques.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fprocesses\u002Ftoken\u002Fimpersonate\u002Fdetect\u002FSKILL.md",[],[155,156,157,86,29,158,101,159,160,161,90,102,162,163,164,165,166,167,168,169],"processes","token","processes token impersonate detect","techniques","escalation","windows","attacks","via","impersonation","potato","exploitation","printspoofer","token-impersonation","seimpersonate","privilege-escalation",{"skillNo":171,"name":172,"nameZh":6,"description":173,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":174,"categories":175,"keywords":176,"publishedAt":35},"01M71HAABSB4Z6QFSXEG00R4RK","processes-thread-injection-detect","Detect Windows thread injection techniques including CreateRemoteThread, QueueUserAPC, NtCreateThreadEx, and thread hijacking via process memory analysis.","https:\u002F\u002Fgithub.com\u002FDCx7C5\u002Fai-marketplace\u002Fblob\u002Fmain\u002Fskills\u002Fwindows\u002Fprocesses\u002Fthread\u002Finjection\u002Fdetect\u002FSKILL.md",[],[177,155,178,86,179,180,91,102,162,181,182,183,115,90,29,158,184,101,185,160],"thread","injection","processes thread injection detect","thread-injection","nt-api","apc-injection","api","process-injection","memory"]