title: JPA Database structure for internationalisation
body: <p>I am trying to get a JPA implementation of a simple approach to internationalisation. I want to have a table of translated strings that I can reference in multiple fields in multiple tables. So all text occurrences in all tables will be replaced by a reference to the translated strings table. In combination with a language id, this would give a unique row in the translated strings table for that particular field. For example, consider a schema that has entities Course and Module as follows :-</p>
  <p><strong>Course</strong>
  int course_id,
  int name,
  int description</p>
  <p><strong>Module</strong>
  int module_id,
  int name</p>
  <p>The course.name, course.description and module.name are all referencing the id field of the translated strings table :-</p>
  <p><strong>TranslatedString</strong>
  int id,
  String lang,
  String content</p>
  <p>That all seems simple enough. I get one table for all strings that could be internationalised and that table is used across all the other tables.</p>
  <p>How might I do this in JPA, using eclipselink 2.4?</p>
  <p>I've looked at embedded ElementCollection, ala this... <a href="http://hwellmann.blogspot.ie/2010/07/jpa-20-mapping-map.html" rel="noreferrer">JPA 2.0: Mapping a Map</a> - it isn't exactly what i'm after cos it looks like it is relating the translated strings table to the pk of the owning table. This means I can only have one translatable string field per entity (unless I add new join columns into the translatable strings table, which defeats the point, its the opposite of what I am trying to do). I'm also not clear on how this would work across entites, presumably the id of each entity would have to use a database wide sequence to ensure uniqueness of the translatable strings table.</p>
  <p>BTW, I tried the example as laid out in that link and it didn't work for me - as soon as the entity had a localizedString map added, persisting it caused the client side to bomb but no obvious error on the server side and nothing persisted in the DB :S</p>
  <p>I been around the houses on this about 9 hours so far, I've looked at this <a href="https://stackoverflow.com/questions/6350415/internationalization-with-hibernate">Internationalization with Hibernate</a> which appears to be trying to do the same thing as the link above (without the table definitions it hard to see what he achieved). Any help would be gratefully achieved at this point...</p>
  <p>Edit 1 - re AMS anwser below, I'm not sure that really addresses the issue. In his example it leaves the storing of the description text to some other process. The idea of this type of approach is that the entity object takes the text and locale and this (somehow!) ends up in the translatable strings table. In the first link I gave, the guy is attempting to do this by using an embedded map, which I feel is the right approach. His way though has two issues - one it doesn't seem to work! and two if it did work, it is storing the FK in the embedded table instead of the other way round (I think, I can't get it to run so I can't see exactly how it persists). I suspect the correct approach ends up with a map reference in place of each text that needs translating (the map being locale-&gt;content), but I can't see how to do this in a way that allows for multiple maps in one entity (without having corresponding multiple columns in the translatable strings table)...</p>