I have an Entity:
public class BookFilter {
@Id
private Integer id;
private List <String> bookId;
private String filterId;
public BookFilter (List <String> bookId, String filterId) {
this.bookId = bookId;
this.filterId = filterId;
}
}
and
public class BookAvailability {
@Id
private Integer id;
private String bookId;
private String type;
private String term;
private Instant dateFrom;
private Instant dateTo;
}
how to optimally store it in the database?
Multiple books can be in multiple filters, and I have to query for filterId to get the bookId list. Something tells me that the JSON field will not be optimal?
CREATE TABLE `asset_global_filter`
(
`id` INTEGER,
`asset_uid` JSON,
`filter_id` VARCHAR(38) NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8;
In the Criteria API, I have a condition that bookId must be equal for both entities and filterId = the specified value. Maybe model it like below? But how do I reflect in an Entity that I have many rows and convert them to a list?
CREATE TABLE `asset_global_filter`
(
`id` INTEGER,
`asset_uid` VARCHAR(255) NOT NULL,
`filter_id` VARCHAR(38) NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB
DEFAULT CHARSET = utf8;