I hope this is a fairly straightforward & newbie JPA question...
I'm trying to figure out how to map either an array of Objects or a List of Objects to an existing database schema.
For simplicity sakes, assuming that my code looks like so:
Code:
@Entity
@Table(name = "USER")
private class User {
@Id
@GeneratedValue
private int userId;
private List<Book> booksCheckedOut; // this can be Book[] booksCheckedOut if that helps
}
private class Book {
@Id
@GeneratedValue
private int bookId;
private String isbn;
}
and the schema for the User table looks like so and it's fixed and cannot be altered:
Code:
USER table:
INT USERID
INT BOOK1ID
INT BOOK2ID
INT BOOK3ID
INT BOOK4ID
INT BOOK5ID
BOOK table:
INT BOOKID
VARCHAR ISBN
How would I go about mapping the Book objects in the User object to the schema? Do I need to do some sort of custom field serialization such that when I retrieve or persist the Book objects it's mapped correctly? Or is my only option to create 5 Book objects in the User class (i.e. Book book1, Book book2 ... Book book5) and then map those to the columns via the @OneToOne annotation?
Thx in advance!
-Warren