gpt4 book ai didi

java - 用于存储月份和月份中的日期的 JPA/Hibernate 映射

转载 作者:行者123 更新时间:2023-12-01 16:12:48 24 4
gpt4 key购买 nike

我有以下 POJO:

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;
}

有没有办法使用 JPA+Hibernate 将这些对象存储到以下数据库结构中:

表格月份:

id;description;

表日:

id-of-month;nr-of-day;info;

对于这种情况有更好的解决方案吗?

最佳答案

如果你不能改变你的 pojo 或表结构,你就有点搞砸了。如果可以的话,一个简单的带注释的 pojo 就可以工作。

class Month {
@Id
private long id;
private String description;
@OneToMany(mappedBy="month",fetchType=Lazy)
private List<Day> days;

}

---- Days 表的代理键需要数据库更改

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

关于java - 用于存储月份和月份中的日期的 JPA/Hibernate 映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/318776/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com