Java – JPA/Hibernate mapping to store months and days-of-months


I have following POJOs:

class Month {
    long id;
    String description;
    List<Day> days; // always contains 29, 30 or 31 elements

class Day {
    byte nr; // possible values are 1-31
    String info;

Is there a way to store these objects into following DB structure using JPA+Hibernate:



Table DAYS:


Any better solution for this situation?

Best Solution

If you can't change your pojo's or table structure you are a bit screwed. If you can then a simple annotated pojo will work.

class Month {
   private long id;
   private String description;
   private List<Day> days;


---- Surrogate key required DB change for Days table

class Day {
    private int id;
    private Month month;
    private byte nr; // possible values are 1-31
    private String info;