Skip to main content

Posts

Showing posts from 2013

javax.validation.ConstraintViolationException: validation failed for classes [*] during update time for groups [javax.validation.groups.Default, ]

This message wasted many hours to figure out the solution. javax.validation.ConstraintViolationException: validation failed for classes [*] during update time for groups [javax.validation.groups.Default, ] When I applied the validation as following, I found that the confirmPassword is the field causing validation error. ValidatorFactory factory = Validation.buildDefaultValidatorFactory();         Validator validator = factory.getValidator();                 Set<ConstraintViolation<User>> constraintViolations = validator.validate(user);         System.out.println("constraintViolations.size : "+constraintViolations.size());         Iterator<ConstraintViolation<User>> iterator = constraintViolations.iterator();         while (iterator.hasNext()) {             ConstraintViolation<dpgsource.users.User> constraintViolation = (ConstraintViolation<dpgsource.users.User>) iterator                     .next();             System.out.println(con

Searching perticular extension file in All or Specified location of system using java program

import  java.io. * ; public   class  SearchFile {      public   static   void   main ( String ... ar )   throws   Exception   {          File  f1  =   new   File ( "F:/" ) ;          printFiles ( f1 ) ;      }      static   void   printFiles ( File  f )   {          File  files []   =  f. listFiles () ;          if   ( files  !=   null )   {              for   ( int  i  =   0 ; i  <  files.length; i ++ )   {                  File  n  =  files [ i ] ;                  if   ( n  !=   null   &   ( n. isDirectory ()   ||  n. isFile ()))   {                      String  s  =  n. getName () ;                      // check for pdf file                      if   ( s. endsWith ( ".pdf" ))   {                          System .out. println ( "  "   +  n. getAbsolutePath ()) ;                      }                      if   ( n. isDirectory ())   {                          printFiles ( n ) ;                      }                  }   

Hibernate - Getting records in sorted order and hibernate pagination.

Hibernate has inbuilt API for ordering and retrieving records in pages.We can use Criteria API to get the result from database instead of Using query or load/get. The things those are applied in SQL queires, same are applied here with the help of Criteria API. You can provide selection conditions to criteria object. You can add order and pagination of records. Here is the simple method for example.   public   List < Contact >   getAll ( int  pageNumber , int  pageSize, boolean  isAsc, String  sortingBy )   {          List < Contact >  l = null ;         Criteria c = currentSession () . createCriteria ( Contact. class ) ;          if ( isAsc ){             c. addOrder ( Order. asc ( sortingBy )) ;          } else {             c. addOrder ( Order. desc ( sortingBy )) ;          }         c. setFirstResult (( pageNumber  -   1 )   *  pageSize ) ;         c. setMaxResults ( pageSize ) ;                  l = c. list () ;          return  l;   }

Code Snippet- Redirection in Spring MVC

    @ RequestMapping ( value  =   "/admin" )      public   String   openDashboard ()   {          return   "redirect:/admin/admin-home" ;      }     @ RequestMapping ( value  =   "/admin/admin-home" )      public   String   adminHome ()   {          return   "dpgsource/admin-dashboard" ;      }     

Spring MVC - Ajax based form processing using JQuery and JSON with server side validation

Spring MVC provides support for processing the form as well as server side validation. It maps request parameters to form backing bean and validate the bean object if we have used @Valid annotation. When we submit the form, form get displayed with the error messages if validation is failed. Error messages are managed by Spring MVC and spring MVC binds them to the input fields. But, If we want to submit the form using ajax request, form page will not refresh and spring MVC cannot send validation error messages to browsers. In this case, server side validation does not work as per my expectations. So here I devised my approach to use the spring MVC validation even in ajax based form submission.  I am using JQuery to serialize the form data and capturing them in controller. In controller, form data is being mapped in User bean and User bean is validated based on field validation annotations. Now if validation is get failed and some errors are appeared there, I collect them in UserJso

WARNING: SQL Error: 1062, SQLState: 23000 SEVERE: Duplicate entry '*' for key '************'

May 14, 2013 4:35:23 PM org.hibernate.util.JDBCExceptionReporter logExceptions WARNING: SQL Error: 1062, SQLState: 23000 May 14, 2013 4:35:23 PM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: Duplicate entry '2' for key 'navigation_id' May 14, 2013 4:35:23 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions SEVERE: Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)     at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:183)     at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Ab