Struts2 hibernate unique key validation
I h开发者_如何学Goave a field say 'mobileno' in table that should be unique.
what is the best way for validation using Struts2 - hibernate validation?
Thanks in advance.
Regards, Vishnu
You could place a unique constraint on the column in the database, but then this won't be checked until you close the transaction. It sounds like you want to check for the purpose of user feedback as well, so the only way to do that is to do a search after the value is entered. Struts validation can't help with this directly since you will need to go to the database. You could have a separate Struts action for checking for duplicates. This could be called from the web page via an ajax call. Pass in the code to check, Struts can route it to a service, Hibernate will do the find and return true or false depending on the results of the search.
精彩评论