java - Best way to represent set of string values in DB and UI -


i'm looking opinions guess 'which better' question. have webapp build in javascript/jquery , struts uses hibernate access data in relational db (mysql). when object/database field has limited set of strings values, better use full string in object/db or 'code' string, single char instead of entire string?

class user {     int    id;     string username;     string type;        // values of 'administrator', 'regular' or     char   type         // values of 'a', 'r' or      char   type         // values of 'a', 'r'     string typestring;  // can returned on fly based on 'type' or db in sql case statement } 

if database has full text string, easy coding way around, wasting space (in db, data transfer) on has few values.

if database has 'code' when presenting field user ( in grid of existing users, or dropdown selection list when creating new user ) char value must converted full string. question should conversion done? @ db level hibernate can fill in full string value case statement. saves db space, not in data transfer or memory. @ object level done in getter/setter 'type' field. or way in gui javascript converts 'char' appropriate string user see.

also... if either method ok use, might influence choice make? number of different values? max length of strings? how many rows expected in table?

i'm sure every db/programmer has come across situation many times , has preference.

if have fixed set of user types admin , regular, think easier use static hashmap in code , store a , r in code. like:

static hashmap<character,string> userroles = new hashmap<>();  static{        userroles.put("a","admin");        userroles.put("r", "regular"); } 

when ever result db, can userroles.get(type) check actual type. saves space , it's readable.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -