Note that there are some explanatory texts on larger screens.

plurals
  1. POInternationalization with Hibernate
    primarykey
    data
    text
    <p>I would like to have something like this be generated from hbm2ddl:</p> <pre><code>______________ ______________ _______________ |Language | |I18N | |Test | -------------- -------------- --------------- |iso3_code:PK|----|iso3_code:PK| |test_id:PK | -------------- |i18n_id:PK |-------|desc_i18n_id | |i18n_text | |-|labl_i18n_id | -------------- --------------- </code></pre> <p>This means more or less that, there is a table language, which holds the iso code and maybe some other info. The i18n table has a foreign key iso3_code on the language table which is also a primary key. The other part of the PK is the i18n_id. The test table then has two foreign keys on the table i18n on the field i18n_id.</p> <p>The output of the parsed hbm2ddl should be like this:</p> <pre><code>public class Test implements java.io.Serializable { private Integer testId; private Map&lt;String,String&gt; label = new HashMap&lt;String,String&gt;(0); private Map&lt;String,String&gt; description = new HashMap&lt;String,String&gt;(0); public Test() { } public Integer getTestId() { return this.testId; } public void setTestId(Integer testId) { this.testId = testId; } public Map&lt;String, String&gt; getLabel() { return label; } public void setLabel(Map&lt;String,String&gt; label) { this.label = label; } public Map&lt;String, String&gt; getDescription () { return description ; } public void setDescription (Map&lt;String,String&gt; description ) { this.description = description ; } } </code></pre> <p>So now the question is, how has my hbm.xml file to look like to generate this table structure and this class. Even if i can not create all resources fully automatically, I would really like to know how this should be declared. I already got it to work for selects, but not for inserts or updates.</p> <pre><code>&lt;class name="test.Test" table="test" catalog="testdb"&gt; &lt;id name="testId" type="java.lang.Integer"&gt; &lt;column name="test_id" /&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;map name="label" table="i18n" fetch="join" cascade="all"&gt; &lt;key column="i18n_id" not-null="true" foreign-key="label_id"/&gt; &lt;map-key column="iso3_code" type="string"/&gt; &lt;element column="i18n_text" type="string"/&gt; &lt;/map&gt; &lt;/class&gt; &lt;class name="test.Lang" table="lang" catalog="testdb"&gt; &lt;id name="iso3Code" type="string"&gt; &lt;column name="iso3_code" length="4" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; &lt;/class&gt; &lt;class name="test.I18n" table="i18n" catalog="testdb"&gt; &lt;composite-id name="id" class="com.blazebit.test.I18nId"&gt; &lt;key-property name="i18nId" type="int"&gt; &lt;column name="i18n_id" /&gt; &lt;/key-property&gt; &lt;key-property name="iso3Code" type="string"&gt; &lt;column name="iso3_code" length="4" /&gt; &lt;/key-property&gt; &lt;/composite-id&gt; &lt;property name="i18nText" type="string"&gt; &lt;column name="i18n_text" /&gt; &lt;/property&gt; &lt;/class&gt; </code></pre> <p>I do not really know why the insert does not work, but maybe it is because the I18nId object which should identify a text, can not be generated. In case of this, i would also accept a solution like this: Map getLabel(){}</p> <p>But with this solution another problem will arise, the i18n_id can not be set by mysql with auto_increment. It would be possible without hibernate.</p> <p>Please anybody help me or give a better practice on how to implement this!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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