1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
@Entity
@Table(name = "category")
public class Category implements Serializable {
// ....................
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "category", orphanRemoval = true)
@MapKey(name = "language")
private Map<Language, CategoryLang> categoryLang;
//................
}
@Entity
@Table(name = "category_lang")
public class CategoryLang implements Serializable {
private static final long serialVersionUID = 6765645529442124861L;
@EmbeddedId
private CategoryLangPK categoryLangPK;
@MapsId("categoryId")
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "category_id", nullable = false)
private Category category;
@MapsId("languageId")
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "lang_id", nullable = false)
private Language language;
@Column(name = "name")
private String name = new String("");
@Column(name = "description")
private String description = new String("");
@Column(name = "link_rewrite", nullable = false, length = 128)
private String linkRewrite = new String("");
@Column(name = "meta_title", length = 128)
private String metaTitle = new String("");
@Column(name = "meta_keywords", length = 255)
private String metaKeywords = new String("");
@Column(name = "meta_description", length = 255)
private String metaDescription = new String("");
//..................................
}
@Embeddable
public class CategoryLangPK implements Serializable {
private static final long serialVersionUID = 4178426371238055474L;
Integer categoryId;
Integer languageId;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((languageId == null) ? 0 : languageId.hashCode());
result = prime * result
+ ((categoryId == null) ? 0 : categoryId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CategoryLangPK other = (CategoryLangPK) obj;
if (languageId == null) {
if (other.languageId != null)
return false;
} else if (!languageId.equals(other.languageId))
return false;
if (categoryId == null) {
if (other.categoryId != null)
return false;
} else if (!categoryId.equals(other.categoryId))
return false;
return true;
}
} |
Partager