Search code examples
javadatabasehibernatespring-roo

can Locale object be stored in database with hibernate


I have following entity:

@RooEntity
Class X {
    @NotNull
    private Locale locale;
}

Is it possible to store toString() representation of Locale object in database and when retrieving I can still get Locale object?

Can I use @Basic annotation here?


Solution

  • You can persist the localeString (or language) to the DB and recreate the Locale object after you fetch your entity.

    As easy as this:

    @RooEntity
    Class X {
        @NotNull
        @Basic
        private String localeString;
    
    
    
        ....
       public Locale getLocaleFromString() {
            return new Locale(localeString);
       }
    }