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