java - How to restrict a user to enter only particular values in a jpa column? -


i restrict user entering values other given set of values jpa column.

for example, if have table this..

sno sname college_name ---------------------- 101 smith stanford 102 jack  harvard 103 tiger stanford 104 scott harvard 

and class..

@entity @table(name="student") public class student { @id @generatedvalue private integer sno; @column(name="sname", nullable=false) private string sname; @column(name="college_name", nullable=false) private string collegename;              // setters , getters omitted } 

is there way, using annotations, restrict user enter either stanford or harvard (case sensitive) college name.

note: instead of writing trigger on database side, want achieve via java program save database call. above entity container managed , sno,sname,college_name persistence fields, not properties.

do have perform check before inserting? looking way?

thanks in advance. hope reply possible.

use enumerated http://tomee.apache.org/examples-trunk/jpa-enumerated/readme.html

btw, wouldn't store string values ("harvard", "stanford") directly in db table. instead use codes (1, 2) , introduce dictionary table with:

code ¦ value 1 harvard 2 stanford


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -