I have the following code
interface Loanable {}
abstract class Material {}
@Entity
class Journal extends Material {}
@Entity
class Book extends Material implements Loanable {}
@Entity
class DigitalMedia extends Material implements Loanable {}
@Entity
@Table(name = "Loan")
@Access(value = AccessType.FIELD)
public class Loan {
@Id
@Column(name="Loan_ID",updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToOne (cascade=CascadeType.ALL)
@JoinColumn(name="studentId")
/* Person who makes the loan */
private User user;
//@Column(name="loanable")
@OneToOne (cascade=CascadeType.ALL)
@JoinColumn(name="materialId")
/* Loanble which is loaned */
private Loanable loanable;
}
As shown in the code, I'm trying to map Loan
to a Loanable
. One User
can have one loan at a time. How can I map the loanable type object to the database? I searched of the method of making an abstract class and extend it in Book
and DigitalMedia
, but I can't extend two classes since they already extend Material
. @Convert
also doesn't seem to work on interface type of objects. I'm using JPA with Hibernate persistence.