@PreAuthorize("hasRole('ROLE_USER')") @RequestMapping(method = RequestMethod.POST) public String saveTrip(@ModelAttribute Trip trip, String startDate) throws ParseException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); User driver = userService.getByLogin(authentication.getName()); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm"); Date date = dateFormat.parse(startDate); long time = date.getTime(); Timestamp start = new Timestamp(time); trip.setStartTime(start); trip.setDriver(driver); List<PassengerNodePoint> points = trip.getPassengerNodePoints(); Iterator iterator = points.iterator(); while (iterator.hasNext()) { PassengerNodePoint point = (PassengerNodePoint) iterator.next(); if (point.getId() == null) { iterator.remove(); } } tripService.save(trip); return "redirect:/user/showTrips"; }