3
请考虑以下两个实体:JPA /休眠@ManyToMany联结表中没有创建索引
@Entity
@Table(name = "PROFILE")
public class Profile extends BaseEntity {
private Long id;
private Set<Tag> tags = new HashSet<Tag>();
@ManyToMany(mappedBy = "taggedProfiles")
public Set<Tag> getTags() {
return tags;
}
public void setTags(Set<Tag> tags) {
this.tags = tags;
}
}
////////////////////////////////////////////////////////////////////////
@Entity
@Table(name = "TAG", uniqueConstraints = @UniqueConstraint(columnNames = {
"TAG_ID", "USERS_ID" }))
public class Tag extends BaseEntity {
private Long id;
private List<Profile> taggedProfiles = new ArrayList<Profile>();
@ManyToMany
@JoinTable(
name = "PROFILE_TAG",
joinColumns = @JoinColumn(name = "TAG_ID"),
inverseJoinColumns = @JoinColumn(name = "PROFILE_ID"),
uniqueConstraints = @UniqueConstraint(
columnNames = {"PROFILE_ID", "TAG_ID" }))
// @ForeignKey(name = "FK__TAG__PROFILE", inverseName = "FK__PROFILE__TAG")
// @Index(name = "IDX__PROFILE__PROFILE_ID")
public List<Profile> getTaggedProfiles() {
return taggedProfiles;
}
/**
* @param taggedProfiles
* the taggedProfiles to set
*/
public void setTaggedProfiles(List<Profile> taggedProfiles) {
this.taggedProfiles = taggedProfiles;
}
}
连接表,PROFILE_TAG
被创建正常,但是,没有创建索引,我希望Hibernate会在连接表上创建一个复合索引。是什么赋予了?
更正:休眠应的两列标记为复合主键,其在转会创建一个聚集索引。 – kmansoor