I'm trying to set up a Spring Boot project using Kotlin and Jakarta Persistence. However, I'm encountering an error when trying to run the application:
Project Setup:
Clue Entity:
import com.jd.jtrivia.models.Category
import jakarta.persistence.*
@Entity
data class Clue(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
val question: String,
val answer: String,
@ManyToOne
val category: Category
)
I've ensured that:
Clue
class is annotated with @Entity
from jakarta.persistence
.Project Structure:
Answer:
It appears the issue was related to an incorrect package import. When working with JPA entities, it's crucial to ensure that the annotations and their associated imports are consistent.
In my case, the correct import for the JPA annotations is from the com.jd.jtrivia.models
package, NOT com.jd.jtrivia.models.Category
. The fixed entity declaration is as follows:
package com.jd.jtrivia.models
import jakarta.persistence.*
@Entity
data class Clue(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
val question: String,
val answer: String,
@ManyToOne
val category: Category
)