一键导入
hibernate
Use for Hibernate/JPA/Flyway work in telegram-home-bot: H2 schema migrations, Kotlin entities, repositories, lazy relations, sequences, entity equality.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use for Hibernate/JPA/Flyway work in telegram-home-bot: H2 schema migrations, Kotlin entities, repositories, lazy relations, sequences, entity equality.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when adding or changing Docker Compose for telegram-home-bot: app service, .env, persistent H2 data, SonarQube profile, bridge/host networking.
Use for Dockerfile and container runtime changes in telegram-home-bot: Raspberry Pi/Linux runtime, fping/iproute2, Gradle bootJar, network mode, ports, logs.
Use when changing database schema, writing Flyway migrations, reviewing SQL migrations, or working with H2 and Spring Boot database startup.
Use for Kotlin code in telegram-home-bot: JVM 17, Spring Boot Kotlin, Gradle Groovy DSL, src/main/java Kotlin layout, null-safety, constructor DI, ktlint.
Use when changing Docker, Docker Compose, runtime configuration, Raspberry Pi deployment, Linux service setup, or lightweight production deployment.
Use for Spring Boot work in telegram-home-bot: configuration, scheduling, security, Thymeleaf, Telegram bot, OpenWeather, actuator, events, testing.
| name | hibernate |
| description | Use for Hibernate/JPA/Flyway work in telegram-home-bot: H2 schema migrations, Kotlin entities, repositories, lazy relations, sequences, entity equality. |
This project uses Hibernate 6.x (managed by Spring Boot 3.5.4) with H2 embedded database. Entities are in random.telegramhomebot.db.model and random.telegramhomebot.auth.db.entities. Flyway manages schema migrations.
GenerationType.SEQUENCE with @SequenceGenerator and allocationSize = 1host_seq, host_time_log_seq, users_seq@Column(updatable = false, nullable = false) on ID fields@Entity
@Table(name = "host")
class Host(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "host_seq")
@SequenceGenerator(name = "host_seq", sequenceName = "host_seq", allocationSize = 1)
@Column(updatable = false, nullable = false)
var id: Long? = null,
// ... fields
)
String?, Long?, Boolean?, List?)id is Long? (null before persistence)@field: target: @field:NotBlank(message = "{...}")@OneToMany(fetch = FetchType.LAZY, mappedBy = "host", cascade = [CascadeType.REMOVE])FetchType.LAZY for collectionsREMOVE for parent-child relationshipsequals and hashCode on natural keys (e.g., mac field in Host)id equality (null before persist)override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || javaClass != other.javaClass) return false
val host = other as Host
return mac == host.mac
}
override fun hashCode(): Int = mac?.hashCode() ?: 0
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface HostRepository : JpaRepository<Host, Long> {
fun findHostByMac(mac: String?): Host?
fun findAllByIpNotNull(): List<Host>
fun findReachableHosts(): List<Host>
}
@Query with JPQL for complex queries:@Query("select h from Host h where h.state = 'REACHABLE'")
fun findReachableHosts(): List<Host>
spring:
datasource:
url: ${DB_URL:jdbc:h2:${user.dir}/thb}
driverClassName: org.h2.Driver
jpa:
hibernate.ddl-auto: validate # Flyway manages schema, Hibernate validates
database-platform: org.hibernate.dialect.H2Dialect
show-sql: false
flyway:
enabled: true
baseline-on-migrate: true
validate-on-migrate: true
src/main/resources/db/migration/V*__Description.sqlV{major}.{minor}__Description.sqlV1.1__Init_DB.sql, V1.2__auth_tables.sqldata class for entities — Hibernate proxy requires regular classes@ManyToOne(fetch = FetchType.EAGER) — always LAZYGenerationType.IDENTITY — use SEQUENCEddl-auto to create or update — Flyway manages schema