Issues with 3 foreign keys in 1 table

Asked by At

Basically, I keep getting the compiling error saying

"Caused by: org.hibernate.AnnotationException: A Foreign key refering PlayingInScreen from Ticket has the wrong number of column. should be 3"

I don't get what it means and I've bee working on it the past 3 hours and its confused the heck out of me.

import java.io.Serializable
import javax.persistence.*

@Entity
@Table(name = "Ticket")
data class Ticket(
        @Id @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "TicketId")
        val ticketId: Long = -1,

        @Id
        @ManyToOne
        @JoinColumn(name = "ScreenId")
        val screenId: PlayingInScreen,

        @Id
        @ManyToOne
        @JoinColumn(name = "TheaterId")
        val theaterId: PlayingInScreen,

        @ManyToOne
        @JoinColumn(name = "StartTime", nullable = false)
        val startTime: PlayingInScreen,

        @ManyToOne
        @JoinColumn(name = "StaffId")
        val staffId: Staff,

        @Column(name = "Price", nullable = false)
        val price: Double = 0.0,

        @Id
        @Column(name = "SellingTimeStamp")
        val sellingTimeStamp: Long = 0) : Serializable
import java.io.Serializable
import javax.persistence.*

@Entity
@Table(name = "PlayingInScreen")
data class PlayingInScreen(
        @Id
        @ManyToOne
        @JoinColumn(name = "ScreenId")
        val screenId: Screen,

        @Id
        @ManyToOne
        @JoinColumn(name = "TheaterId")
        val theaterId: Screen,

        @ManyToOne
        @JoinColumn(name = "MovieId")
        val movieId: Movie,

        @Id
        @Column(name = "StartTime", nullable = false)
        val startTime: Long = 0) : Serializable {

    @OneToMany(mappedBy = "startTime")
    private val startTimes: Set<Ticket> = emptySet()

    @OneToMany(mappedBy = "theaterId")
    private val theaterIds: Set<Ticket> = emptySet()

    @OneToMany(mappedBy = "screenId")
    private val screenIds: Set<Ticket> = emptySet()
}

Project Requirements: PlayingInScreen: ScreenId Char (8) Pk, Fk (Screen) TheaterId Char (8) Pk, Fk (Screen)

Ticket: TheaterId Char (8) Pk, Fk (PlayingInScreen) ScreenId Char (8) Pk, Fk (PlayingInScreen) StartTime Date Not Null, Fk(PlayingInScreen)

0 Answers