Skip to content

Latest commit

 

History

History
109 lines (83 loc) · 3.93 KB

jpa.md

File metadata and controls

109 lines (83 loc) · 3.93 KB

JPA

한국어

Generate Kotlin

$ oct generate kt --help
Option Env. Variable Description
-i, --input OCTOPUS_INPUT Octopus schema file to read
-o, --output OCTOPUS_OUTPUT Target file or directory
-a, --annotation OCTOPUS_ANNOTATION Custom Entity class annotation.
Format: {group1}:{annotations1}[,{group2}:{annotations2}]...
-g, --groups OCTOPUS_GROUPS Table groups to generate.
Set multiple groups with comma(,) separated.
-e, --idEntity OCTOPUS_ID_ENTITY Interface NAME with id field
-p, --package OCTOPUS_PACKAGE Entity class package name
-f, --prefix OCTOPUS_PREFIX Class name prefix.
Format: {group1}:{prefix1}[,{group2}:{prefix2}]...
-l, --relation OCTOPUS_RELATION Virtual relation annotation type.
Available values: VRelation
-d, --removePrefix OCTOPUS_REMOVE_PREFIX Prefixes to remove from class name.
Set multiple prefixes with comma(,) separated.
-r, --reposPackage OCTOPUS_REPOS_PACKAGE Repository class package name. Skip if not set.
-q, --uniqueNameSuffix OCTOPUS_UNIQUE_NAME_SUFFIX Unique constraint name suffix
-u, --useUTC OCTOPUS_USE_UTC Set flag to use UTC for audit columns (created_at, updated_at).
Default: false

Example

$ oct generate kt \
    --input examples/user.json \
    --output output/ \
    --package octopus.entity \
    --reposPackage octopus.repos \
    --useUTC

Generated *.kt files:

UserGroup.kt

package octopus.entity

import javax.persistence.*

@Entity
@Table(name="group", uniqueConstraints = [
    UniqueConstraint(name = "group", columnNames = ["name"])
])
data class UserGroup(
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(nullable = false)
        var id: Long = 0L,

        @Column(nullable = false, length = 40)
        var name: String = ""
)

User.kt

package octopus.entity

import javax.persistence.*

@Entity
@Table(name="user", uniqueConstraints = [
    UniqueConstraint(name = "user", columnNames = ["name"])
])
data class User(
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(nullable = false)
        var id: Long = 0L,

        @Column(nullable = false, length = 40)
        var name: String = "",

        var groupId: Long?
)

UserGroupRepository.kt

package octopus.repos

import octopus.entity.*
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface UserGroupRepository : JpaRepository<UserGroup, Long>

UserRepository.kt

package octopus.repos

import octopus.entity.*
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface UserRepository : JpaRepository<User, Long>