Internationalization with Hibernate

前端 未结 1 1214
独厮守ぢ
独厮守ぢ 2020-12-14 14:12

I would like to have something like this be generated from hbm2ddl:

______________    ______________       _______________
|Language    |    |I18N        |           


        
相关标签:
1条回答
  • 2020-12-14 14:27

    I know my question is very old, but probably someone finds this and wants to know how to do that!

    Well my final solution is creating embedded or composite elements within a map. Pretty easy, but you have to know how to do that. Here is an example on how to do that with annotations:

    @Entity
    @Table(name="A")
    public class A implements Serializable{
    
        private Map<Locale, LocalizedA> localized = new HashMap<Locale, LocalizedA>();
    
        @ElementCollection
        @CollectionTable(name = "localized_a")
        @MapKeyJoinColumn(name = "field_name_for_locale")
        public Map<Locale, LocalizedA> getLocalized() {
            return this.localized;
        }
    
        public void setLocalized(Map<Locale, LocalizedA> localized) {
            this.localized = localized;
        }
    
    }
    
    
    @Embeddable
    public class LocalizedA implements java.io.Serializable {
    
        @Column(name = "field_name_for_description")
        public String getDescription() {
            return this.description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    }
    

    I hope this will help someone, if you want an example for hbm.xml files just comment and i will add that.

    0 讨论(0)
提交回复
热议问题