Multiple variables to one table in a single class in spring boot

Viewed 22

I've created a lookup table called time intervals:

@Entity
@Table(name = "lookup_time_interval")
data class TimeInterval(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "time_interval_id")
    val id: Long? = null,

    @Column(name = "time_interval_name")
    var name: String = "",
)

I also have a StockItem entity which I'd like to have multiple variables pointing to this lookup table as they all essentially have the same data:

    @Column(name = "stock_item_service_interval")
    var serviceInterval: TimeInterval? = null, // TODO: Create lookup for service interval

    @Column(name = "stock_item_pat_test_interval")
    var patTestInterval: TimeInterval? = null, // TODO: Create lookup for PAT Test Interval

    @Column(name = "stock_item_test_interval")
    var testInterval: TimeInterval? = null, // TODO: Create lookup for test interval

I've initialised the lookup table with a repository. However, I realised that I cannot use a OneToMany/ManyToOne relationship as it seems to only take one mappedBy reference and I cannot seem to add another as needed.

How could I achieve this so that I'm not having to use multiple tables with the exact same data in it?

Thanks

0 Answers
Related