I've poured over the Hibernate docs and I can't find a solution to this problem. I've tried several different solutions with the hibernate mappings but I can't figure it out.
Basically, I'm working with
Brands that can have a different
name depending on the current language (ie. the name is translated to whatever language we're currenlty using). Here is the Java class and the two SQL tables:
Code:
JAVA
public class Brand {
private Integer id; // unique ID per brand
private Integer languageId; // unique ID per language, always set to the current language
private String enabled; // flag, true if we display this to html
private Integer ranking; // ranking to display in html
private String name; // the translated name of this brand
// .... Getters and Setters
}
SQL
brand
{
brand_id // int, auto_increment, primary key
ranking // int
enabled // char(3)
}
brandtext
{
brand_id // int, foreign key
language_id // int, foreign key
name // varchar(255), a translation of this brand's name
}
Basically I want the following behavior:
1) when I load a Java Brand object, I want to load the static data from the
brand table and then use the class's
language_id property to load the translated
name2) when I delete a Java
brand object, I want to delete the entry in the
brand table, as well as all entires in the
brandtext table that correspond to the
brand_id3) when saving a
Brand, I want both tables' values to be updated
I know there must be a way for hibernate to map these properties, although I'm not sure about getting all of the desired behavior... If someone could point me in the right direction I'd be very appreciative. I'm fairly sure this is wrong, but here is the current mapping:
Code:
<hibernate-mapping package="foobar">
<class name="Brand" table="brand">
<id name="id" column="brand_id" type="int">
<generator class="identity"/>
</id>
<property name="enabled" type="string"/>
<property name="ranking" type="int"/>
<join table="brandtext" inverse="true" >
<key column="brand_id" on-delete="cascade"/>
<property name="languageId" column="language_id" type="int"/>
<property name="name" type="string"/>
</join>
</class>
</hibernate-mapping>
* this is the last semi-working edition, I realize it doesn't handle the composit key correctly