Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate mapping for multilanguage support
    text
    copied!<p>I have a Category class which has id, name, description attributes.</p> <p>I want that user can enter multilingual <strong>name and description</strong> and save them.</p> <p>What should be the structure of the class and the hibernate mapping?</p> <p>This is my code with annotations. But I couldn't insert anything to database:</p> <pre><code>@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&lt;String, TranslatedString&gt; name; private Map&lt;String, TranslatedString&gt; description; @ElementCollection @CollectionTable(name = "translated_string") @MapKeyJoinColumn(name = "langCode") public Map&lt;String, TranslatedString&gt; getName() { return this.name; } public void setName(Map&lt;String, TranslatedString&gt; name) { this.name = name; } @ElementCollection @CollectionTable(name = "translated_string") @MapKeyJoinColumn(name = "langCode") public Map&lt;String, TranslatedString&gt; getDescription() { return this.description; } public void setDescription(Map&lt;String, TranslatedString&gt; 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; } } </code></pre> <p>I have two tables: translated_string : tid, text, langCode category: id, name_id, description_id</p> <p>I am getting this info message: Hibernate: insert into category values ( ) when I want to save the category by hibernateTemplate.</p> <p>And when I want to find a category by id, it executes</p> <pre><code>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=? </code></pre> <p>Since my translated_string table doesn't have Category_id or name_KEY fields, i think I have a problem with the mapping.</p> <p>Where am I wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload