Hi theBernd,
First of all,
Quote:
references translation_id in translation which isn't a PK either and not unique
Well, if translation_id in translation isn`t unique, you shouldn't using a set. A set doesn't allows duplicate elements.
Second,
Quote:
translation_id plus locale_id gives an alternate key, but...)
I would like to know what is the end of your sentence here, but here is what I would suggest. Use a composite-key for your set and override .equals() and .hashcode in the translation object to reflect the translation table natural key (translation_id + locale_id) :
Code:
public class Translation implement Serializable
{
private Serializable id; // i prefer to use Serializable for ids because this let me change its implementation later without altering this code
private Serializable translationId;
private Serializable localeId; // you should consider using a java.util.Locale object...
[...]
public boolean equals( Object o )
{
if( this == o ) return true;
if( !(o instanceof Translation) ) return false;
Translation other = (Translation)o;
return getTranslationId().equals( other.getTranslationId() )
&& getLocaleId().equals( other.getLocaleId() );
}
public int hashCode()
{
int result;
result = getTranslationId();
result = 29 * result + getLocaleId();
return result;
}
}
Then, map your set in the list_something object this way:
Code:
<set name="translations" table="translation"> <!-- use cascade, inverse, etc as necessary-->
<key>
<column name="translation_id"/>
<column name="locale_id"/>
</key>
<one-to-many
class="Translation"/>
</set>
Let me know about it,