java - Proper way to restrict member value to subset of set -
say have person object field profession, list of strings. canonical way, using spring , hibernate, restrict list subset of professions defined either user or admin? ie, list of global, predefined professions @ runtime {accountant, developer}, , user adds 'plumber' list. if new person created, i'd restrict possible professions person can have 3 in list.
originally, implemented enum, seems poor design, it's generated @ compile time, , can't added @ run time (i think?). proper way define 1 column table profession, , @ each request make person, populate singleton 1 member, list of professions? domain object person source profession singleton (presumably in service layer?).
you can create new entity profession related person one-to-many relationship. way profession persisted hibernate. profession entity not need much. id , name now. later might add more attributes need.
Comments
Post a Comment