Since I am new to this framework i am not getting proper examples, can anyone tell me how to avoid duplicate username insertion in to DB? I just selected the username from the DB and put it into the List, now I just want to validate it for duplicate insertion and throw a message if there is already a name exists in DB.
ArrayList namelist = new ArrayList();
String name1 = "select P.name from Person P;
Query q1 = em.createQuery(name1);
namelist.addAll(q1.getResultList());