Java: how to validate list of object against schema before saving it in database?

Table:

  • Employee { emp_id(len 5), Name(len 45), City(Len 30) }

  • Salary { Id (len 5), Emp_id(len 5), Amount(len 8) }

I have Entity class of both the tables in Java generated by hibernate and I need to bulk insert data (From Excel sheet) into the database and before inserting I want to validate the whole data set (like has attribute length as allowed by the Database, not null constraint etc) against database constraint.

What will be the best/optimal way of doing so?

Take a look at Hibernate Validator (http://hibernate.org/validator/).

You should be able to annotate your entities with whatever validation rules you need.