Db-level internationalization in playback structure

Is there a clean solution for multilingual fields in JPA?

I think of this db structure:

tabular product

+---------+--------------+-----+ | Field | Type | Key | +---------+--------------+-----+ | id | bigint(20) | PRI | | price | varchar(255) | | +---------+--------------+-----+ 

table product_lang

 +------------------+--------------+-----+ | Field | Type | Key | +------------------+--------------+-----+ | id | bigint(20) | PRI | | lang | varchar(3) | PRI | | title | varchar(255) | | | description | varchar(255) | | +------------------+--------------+-----+ 

And this is the class I would like to use:

 @Entity public class Product { @Id public Long id; public Double price; public Locale lang; @Translateable public String title; @Translateable public String description; } 
+4
source share
2 answers

I'm not sure if you can map one Entity to two tables as you suggest. Just like what you want, you can store translations as:

 @CollectionOfElements Map<String, String> titles; 

where the key is the line for Lang that the user is browsing with, and the value that will be shown in the header. This would create two tables in the database and provide quick access to translations.

0
source

IMO, wrong decision. If you really want to have db internationalized, I would prefer to create several databases, rather than one large one containing all the data.

Just check langage to get the correct DB connection.

0
source

All Articles