how do i set up a one to one with superclass in kotlin

618 Views Asked by At

I have different user types Author and Commentor. I wanted them to have a OneToOne relationship with my User class. The user class would contain spring security logic. I created a super class of BlogUser and my Author and Commenter would extend it. When i try and set up the hibernate mappings I get:

Unknown mappedBy in: com.legge.blenderBlog.models.security.User.blogUser, referenced property unknown: com.legge.blenderBlog.models.abstract.BlogUser.user

Is my thinking wrong?

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class BlogUser(
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        val id: Long = 0,

        @OneToOne(fetch=FetchType.LAZY)
        @JoinColumn(name="USER_ID")
        val user: User


) : DateAudit()

here is my Author.kt

@Entity
@Table(name = "author")
class Author(user:User
): BlogUser(user = user)

here is part of the User class

@Entity
@Table(name = "sec_user", uniqueConstraints = [(UniqueConstraint(columnNames = arrayOf("username"))), (UniqueConstraint(columnNames = arrayOf("email")))])
open class User(

        ....

        @OneToOne(fetch=FetchType.LAZY, mappedBy="user")
        var blogUser: BlogUser?,

        ...

) : DateAudit()

Here is dateAudit

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
@JsonIgnoreProperties(value = ["dateCreated", "dateUpdated"], allowGetters = true)
abstract class DateAudit : Serializable {
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_created", nullable = false, updatable = false)
    @CreatedDate
    var dateCreated: Date = Date()

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_updated", nullable = false)
    @LastModifiedDate
    var dateUpdated: Date = Date()
}
0

There are 0 best solutions below