【发布时间】:2015-01-13 06:33:48
【问题描述】:
在数据库中,我有以下三个表,其中User 和Profile 具有多对多关系,并与User_Profile 连接如下:
User User_Profile Profile
---- ------------ -------
user_id user_id profile_id
user_name profile_id profile_description
user_time
使用UserHbm 和ProfileHbm 类:
@Entity
@Table(name = "User")
public class UserHbm {
@Id
@GeneratedValue(generator = "id-generator")
@GenericGenerator(name = "id-generator",
strategy = "com.xx.xxx.XXXSequenceGenerator",
parameters = { @Parameter(name = "sequenceName", value = "User") })
@Column(name = "user_id")
private long user_id;
@Column
private String user_name;
@Column
private Date user_time;
@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinTable(name="User_Profile",
joinColumns = { @JoinColumn(name = "identityProfileID") },
inverseJoinColumns={@JoinColumn(name="profile_id")})
private Set<ProfileHbm> profiles = new HashSet<ProfileHbm>();
//irrelevant other codes
}
@Entity
@Table(name = "Profile")
public class ProfileHbm {
@Id
@GeneratedValue(generator = "id-generator")
@GenericGenerator(name = "id-generator",
strategy = "com.xx.xxx.XXXSequenceGenerator",
parameters = { @Parameter(name = "sequenceName", value = "Profile") })
@Column(name = "profile_id")
private long profile_id;
@Column
private String profile_description;
//irrelevant other codes
}
到目前为止,一切都很好,直到出现新要求:将 user_time 放入 User_Profile 以便架构看起来像:
User User_Profile Profile
---- ------------ -------
user_id user_id profile_id
user_name profile_id profile_description
user_time user_time
谁能告诉我如何做到这一点?
我是否必须创建另一个中介 HBM 来执行此操作?
【问题讨论】:
-
user_time 中有哪些数据?
-
只是日期类型的用户更新时间
-
User Table 和 user_profile 表中的 user_time 是否都是相同的数据。 ?如果是这样,您可以从用户表中获取它吗?为什么要再次出现在 user_profile 表中
-
@Ramesh
User_Profile上还有另一个触发器用于审计目的
标签: hibernate jpa join many-to-many