我想映射一个Java映射表,其中所有键值存储在同一个表中。 与https://en.wikibooks.org/wiki/Java_Persistence/Relationships#Example_of_a_map_key_column_relationship_database 类似的东西,但关键是一个对象,而不是一个简单的类型。Jpa Hibernate映射键多列关系
说我有一个实体的 “用户”
@Entity
public class User{
@Id
private String userId;
@OneToMany
@MapKeyClass(CalenderWeek.class)
private Map<CalenderWeek, WorkedTime> workedTimeMap;
关键CalendarWeek会是这样的
@Embeddable
public class CalenderWeek {
int year;
Month month; // Month is the enum java.time.Month
的WorkedTime会是这样的
@Embeddable
public class WorkedTime {
private long workedHours;
相应的工作时间表应该是这样的
worked_time
user_id | year | month | worked_hours
---------|------|-------| ---
1 | 2017 | 11 | 42
是否有可能拿到 或做我必须做如下描述 https://en.wikibooks.org/wiki/Java_Persistence/Relationships#Example_of_a_map_key_class_embedded_relationship_annotation
即,三个用表。
只是为了让它完成@CollectionTable( 名= “worked_time”, joinColumns = @ JoinColumn(名=“user_id”) ) 也是需要的。 – fan