I'm simplyfing, but I have the following db:
Code:
create table text
(
id integer primary key,
type_id integer,
reference_id integer,
language_code char(2),
value varchar(255)
);
create table recipe
(
id integer primary key
);
As for objects, I currently have:
@Entity
@Table(name="text")
class LocalizedText
{
int textType;
@Id
int id;
int reference_id;
String languageCode;
String value;
}
@Entity
@Table(name="recipe")
class Recipe
{
@Id
int id;
@OneToMany(targetEntity=LocalizedText)
@JoinColumn(name="reference_id", insertable=false, updatable=false)
@Cascade(CascadeType.ORPHAN)
@Where(type_id=1)
@MapKey(name="language_code")
Map<String, LocalizedText>name;
}
Now, here's the question.
I'd like to move the map into its own object, i.e. have a special object to keep track of my localized strings, something like:
Code:
public class Text
{
...
...
int typeId;
int referenceId;
Map<String, LocalizedText>values;
public toString(String languageCode)
{
return values.get(languageCode);
}
public class Recipe
{
int id;
Text name;
Text description;
Text instructions;
}
public class Ingredient
{
int id;
Text name;
}
But I have no idea what to do with my Text class, my first thought is that it has to extend AbstractPersistentCollection or something like that, and then the annotations would look something similar to the same annotations I have originally for the map (with the OneToMany and so on) but I'm not sure. Any ideas?