I have a database diagram, which i need to implement in Entity classes
User entity:
@Entity
class User (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val idUser: Int = -1,
@Column(unique=true)
val name: String = "",
@Column(unique=true)
val email: String = "",
@Column(nullable = false)
val password: String = ""
)
Post entity: User entity:
@Entity
data class Post (
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val idPost: Int = -1,
@Column(nullable = false)
val title: String = "",
@Column(nullable = false)
val body: String = "",
@Column(nullable = false)
val date: String = Date().toString()
)
I just don't understand how to organize a relationship between tables. Also IDEA reports an error when a table does not have Primary Key.
Help me with implementation of UserPost Entity class.
EDIT - 1
Okay, I have a solution, just add a data source (I used MySQL) and use Generate Kotlin Entities.kts then IDEA will automatically create all Entity classes. I think it is the most easy way.
