我有一個具有id,name,description屬性的Category類。支持多語言的Hibernate映射
我想讓用戶可以輸入多種語言名稱和說明並保存它們。
應該是什麼類的結構和hibernate映射?
這是帶註釋的代碼。但我不能插入什麼數據庫:
@Entity
@Table(name = "category")
public class Category {
@Id
@GeneratedValue
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private Integer id;
private Map<String, TranslatedString> name;
private Map<String, TranslatedString> description;
@ElementCollection
@CollectionTable(name = "translated_string")
@MapKeyJoinColumn(name = "langCode")
public Map<String, TranslatedString> getName() {
return this.name;
}
public void setName(Map<String, TranslatedString> name) {
this.name = name;
}
@ElementCollection
@CollectionTable(name = "translated_string")
@MapKeyJoinColumn(name = "langCode")
public Map<String, TranslatedString> getDescription() {
return this.description;
}
public void setDescription(Map<String, TranslatedString> description) {
this.description = description;
}
}
@Embeddable
public class TranslatedString {
public Integer getTid() {
return tid;
}
public void setTid(Integer tid) {
this.tid = tid;
}
private Integer tid;
private String langCode;
@Column(name = "langCode")
public String getLangCode() {
return langCode;
}
public void setLangCode(String langCode) {
this.langCode = langCode;
}
private String text;
@Column(name = "text")
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
我有兩個表: translated_string:TID,文字的langCode 類:身份證,名_ID,description_id
我得到這個信息的消息: 休眠:當我想通過hibernateTemplate保存類別時,插入類別值() 。
當我想找到ID的類別,它執行
select
name0_.Category_id as Category1_0_0_,
name0_.langCode as langCode0_,
name0_.text as text0_,
name0_.tid as tid0_,
name0_.name_KEY as name5_0_
from translated_string name0_
where name0_.Category_id=?
由於我translated_string表沒有CATEGORY_ID或name_KEY領域,我想我已經用映射的一個問題。
我在哪裏錯了?
好問題!我的猜測是你需要爲每種語言創建一個索引(除非你想混合它們),但不知道映射,可能在映射文件中使用request_locale? – 2012-01-14 16:27:58
什麼是TransaltedString? – Firo 2012-01-18 11:09:08