Hi, I tried to generate metamodel using org.hibernate:hibernate-jpamodelgen and kapt, I followed this doc:
https://kotlinlang.org/docs/reference/kapt.html
but my metamodel wasn’t generated, follow my class and my build.gradle
build.gradle:
buildscript {
ext {
kotlinVersion = '1.3.21'
springBootVersion = '2.1.2.RELEASE'
dagger_version = '2.11'
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}")
}
}
apply plugin: "kotlin-allopen"
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'kotlin-jpa'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'kotlin-kapt'
apply plugin: 'idea'
group = 'br.com.blog'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.9'
repositories {
mavenCentral()
}
ext{
junitVersion = '5.3.2'
junitLaucherVersion ='1.3.2'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
dependencies {
kapt "org.hibernate:hibernate-jpamodelgen"
kaptTest "org.hibernate:hibernate-jpamodelgen"
implementation "org.hibernate:hibernate-jpamodelgen"
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
implementation 'org.flywaydb:flyway-core'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect"
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'org.postgresql:postgresql'
testImplementation ("org.springframework.boot:spring-boot-starter-test"){
exclude module: "junit"
}
testCompile "com.h2database:h2:1.4.197"
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile "org.junit.platform:junit-platform-launcher:${junitLaucherVersion}"
}
compileKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
tag.lt:
package br.com.blog.blogapi.model
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.ManyToMany
import javax.persistence.Table
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size
@Entity
@Table(name = "tags")
data class Tag (
@Column(nullable = false, length = 140)
@NotNull
@Size(min = 2, max = 140)
var descricao: String
){
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var codigo : Long = 0
@ManyToMany
var posts: List<Post> = emptyList()
}
post.kt:
package br.com.blog.blogapi.model
import java.time.LocalDateTime
import javax.persistence.CascadeType
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.JoinColumn
import javax.persistence.JoinTable
import javax.persistence.ManyToMany
import javax.persistence.ManyToOne
import javax.persistence.PrePersist
import javax.persistence.PreUpdate
import javax.persistence.Table
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size
@Entity
@Table(name = "POSTS")
data class Post (
@Column(nullable = false, length = 140)
@NotNull
@Size(min = 2, max = 140)
var titulo : String,
@Column(nullable = false)
@NotNull
var descricao: String,
@ManyToOne
@JoinColumn(name = "codigo_pessoa")
var pessoa: Pessoa
){
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var codigo : Long = 0
@ManyToMany(cascade = [CascadeType.MERGE, CascadeType.PERSIST])
@JoinTable(name = "POSTS_TAGS",
joinColumns = [JoinColumn(name = "CODIGO_POST")],
inverseJoinColumns = [JoinColumn(name = "CODIGO_TAG")])
var tags: List<Tag> = emptyList()
@Column
var dataEdicao: LocalDateTime? = null
@Column
var dataCriacao: LocalDateTime? = null
@PrePersist
fun onCreate(){
dataCriacao = LocalDateTime.now()
}
@PreUpdate
fun onUpdate(){
dataEdicao = LocalDateTime.now()
}
}
Pessoa.kt:
package br.com.blog.blogapi.model
import javax.persistence.CascadeType
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.GenerationType
import javax.persistence.Id
import javax.persistence.OneToMany
import javax.persistence.Table
import javax.validation.constraints.Email
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size
@Entity
@Table(name = "pessoas")
data class Pessoa (
@Column(nullable = false, length = 140)
@NotNull
@Size(min = 2, max = 140)
var nome : String,
@Column(nullable = false, length = 140)
@NotNull
@Email
@Size(min = 2, max = 140)
var email : String,
@Column(nullable = false, length = 40)
@NotNull
@Size(min = 8, max = 40)
var senha : String
){
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var codigo : Long = 0
@OneToMany(mappedBy = "pessoa", cascade = [CascadeType.ALL], orphanRemoval = true)
var posts : List<Post> = emptyList()
}
thank you