spring – java.lang.NoClassDefFoundError: java/sql/Time Exception when trying to send a PATCH request

I’m trying to make an application which updates an Entity. Server is made using Spring Boot. I’m trying to send a PATCH request using Unirest, but I’m getting this exception:

Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: java/sql/Time
    at com.google.gson.Gson.<init>(Gson.java:265)
    at com.google.gson.Gson.<init>(Gson.java:186)
    at unirest.java@3.13.6/kong.unirest.json.CoreFactory$JavaTypeAdapter.<init>(CoreFactory.java:54)
    at unirest.java@3.13.6/kong.unirest.json.CoreFactory.<clinit>(CoreFactory.java:42)
    at unirest.java@3.13.6/kong.unirest.json.JSONElement.<clinit>(JSONElement.java:38)
    at unirest.java@3.13.6/kong.unirest.JsonNode.<init>(JsonNode.java:41)
    at unirest.java@3.13.6/kong.unirest.JsonResponse.getNode(JsonResponse.java:40)
    at unirest.java@3.13.6/kong.unirest.JsonResponse.<init>(JsonResponse.java:35)
    at unirest.java@3.13.6/kong.unirest.apache.BaseApacheClient.transformBody(BaseApacheClient.java:60)
    at unirest.java@3.13.6/kong.unirest.apache.ApacheClient.request(ApacheClient.java:132)
    at unirest.java@3.13.6/kong.unirest.Client.request(Client.java:57)
    at unirest.java@3.13.6/kong.unirest.BaseRequest.request(BaseRequest.java:359)
    at unirest.java@3.13.6/kong.unirest.BaseRequest.asJson(BaseRequest.java:244)
    at AplikacjaDoLogowania/com.Controller.FXMLImageMenuController.lambda$updateWindow$3(FXMLImageMenuController.java:176)
    at javafx.base@19-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base@19-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at javafx.base@19-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base@19-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@19-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@19-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@19-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@19-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@19-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@19-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@19-ea/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@19-ea/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base@19-ea/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@19-ea/javafx.scene.Scene$KeyHandler.process(Scene.java:4089)
    at javafx.graphics@19-ea/javafx.scene.Scene.processKeyEvent(Scene.java:2146)
    at javafx.graphics@19-ea/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2614)
    at javafx.graphics@19-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:218)
    at javafx.graphics@19-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:150)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics@19-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:250)
    at javafx.graphics@19-ea/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    at javafx.graphics@19-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:249)
    at javafx.graphics@19-ea/com.sun.glass.ui.View.handleKeyEvent(View.java:542)
    at javafx.graphics@19-ea/com.sun.glass.ui.View.notifyKey(View.java:966)
    at javafx.graphics@19-ea/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@19-ea/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: java.sql.Time
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 41 more

I don’t know why it’s behaving like that because I’m not updating any time value

Entity from server:

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;

@Entity
public class Entity{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private int scannerNumber;
    private String loggedUser;
    private boolean inService;
    private LocalDateTime timeOfLogin;

    public Entity() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getScannerNumber() {
        return scannerNumber;
    }

    public void setScannerNumber(int scannerNumber) {
        this.scannerNumber = scannerNumber;
    }

    public String getLoggedUser() {
        return loggedUser;
    }

    public void setLoggedUser(String loggedUser) {
        this.loggedUser = loggedUser;
    }

    public boolean isInService() {
        return inService;
    }

    public void setInService(boolean inService) {
        this.inService = inService;
    }

    public LocalDateTime getTimeOfLogin() {
        return timeOfLogin;
    }

    public void setTimeOfLogin(LocalDateTime timeOfLogin) {
        this.timeOfLogin = timeOfLogin;
    }
}

Controller from server:

@RestController
public class EntityController{
    private static final Logger logger = LoggerFactory.getLogger(ScannerController.class);
    private final EntityRepository repository;

    public EntityController(EntityRepository repository) {
        this.repository = repository;
    }

    @GetMapping("/scanners")
    ResponseEntity<List<Scanner>> findAll(){
        return ResponseEntity.ok(repository.findAll());
    }
    @GetMapping("/scanners/{id}")
    ResponseEntity<?> findById(@PathVariable int id){
        if (repository.existsById(id)){
            return ResponseEntity.ok(repository.findById(id));

        } else {
            logger.warn("Brak skanera o podanym numerze");
            return ResponseEntity.notFound().build();
        }
    }
    @GetMapping("/scanners/service/{param}")
    ResponseEntity<List<Entity>> findByInService(@PathVariable boolean param){
        return ResponseEntity.ok(repository.findByInService(param));
    }
    @PatchMapping("/scanners/{id}")
    ResponseEntity<?>updateScanner(@PathVariable int id, @Valid Entity toUpdate){
        if (repository.existsById(id)){
            if(!repository.findById(id).get().isInService()){
                Entity entity = toUpdate;
                entity.setTimeOfLogin(LocalDateTime.now());
                entity.setId(id);
                repository.save(entity);
                return ResponseEntity.noContent().build();
            } else {
                logger.info("Device in service");
                return ResponseEntity.badRequest().build();
            }

        } else {
            return ResponseEntity.notFound().build();
        }

    }

and my PATCH request from an client application:

HttpResponse<JsonNode> request = Unirest.patch("http://localhost:8080/scanners/" + entity.getId())
                        .header("accept", "application/json")
                        .field("loggedUser", loggedUserTextField.getText())
                        .asJson();

Leave a Comment