title: SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/restapp] threw exception [java.util.NoSuchElementException]
body: <p>This is my first REST API application , i am trying to build brand and products application, where all products in table belongs any brands in the another table.
  I am testing this application in postman.
  While getting the results by providing particular brand id it is throwing this error.</p>
  <pre><code>SEVERE: Servlet.service() for servlet [Jersey Web Application] in context with path [/restapp] threw exception [java.util.NoSuchElementException] with root cause
  java.util.NoSuchElementException
      at org.glassfish.json.JsonParserImpl.next(JsonParserImpl.java:361)
      at org.eclipse.yasson.internal.JsonbRiParser.next(JsonbRiParser.java:140)
      at org.eclipse.yasson.internal.Unmarshaller.getRootEvent(Unmarshaller.java:66)
      at org.eclipse.yasson.internal.Unmarshaller.deserializeItem(Unmarshaller.java:56)
      at org.eclipse.yasson.internal.Unmarshaller.deserialize(Unmarshaller.java:50)
      at org.eclipse.yasson.internal.JsonBinding.deserialize(JsonBinding.java:45)
      at org.eclipse.yasson.internal.JsonBinding.fromJson(JsonBinding.java:85)
      at org.glassfish.jersey.jsonb.internal.JsonBindingProvider.readFrom(JsonBindingProvider.java:99)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.invokeReadFrom(ReaderInterceptorExecutor.java:257)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:236)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
      at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundReadFrom(MappableExceptionWrapperInterceptor.java:73)
      at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:156)
      at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1091)
      at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
      at org.glassfish.jersey.server.ContainerRequest.readEntity(ContainerRequest.java:271)
      at org.glassfish.jersey.server.internal.inject.EntityParamValueParamProvider$EntityValueSupplier.apply(EntityParamValueParamProvider.java:97)
      at org.glassfish.jersey.server.internal.inject.EntityParamValueParamProvider$EntityValueSupplier.apply(EntityParamValueParamProvider.java:80)
      at org.glassfish.jersey.server.spi.internal.ParamValueFactoryWithSource.apply(ParamValueFactoryWithSource.java:74)
      at org.glassfish.jersey.server.spi.internal.ParameterValueHelper.getParameterValues(ParameterValueHelper.java:92)
      at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$AbstractMethodParamInvoker.getParamValues(JavaResourceMethodDispatcherProvider.java:133)
      at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:243)
      at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:104)
      at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:277)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272)
      at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:316)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:298)
      at org.glassfish.jersey.internal.Errors.process(Errors.java:268)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289)
      at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703)
      at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416)
      at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342)
      at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  <p>This is my Brands.java file</p>
  <pre><code>package shrikant.restapp.showroon.resoursces;
  
  import java.net.URI;
  import java.util.List;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.DELETE;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.PUT;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import javax.ws.rs.core.UriInfo;
  
  import shrikant.restapp.showroon.hibernate.entities.BrandEntity;
  import shrikant.restapp.showroon.services.BrandsService;
  
  @Path(&quot;/showroom/brands&quot;)
  public class Brands {
  
      BrandsService service = new BrandsService();
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public List&lt;BrandEntity&gt; getBrands() {
          List&lt;BrandEntity&gt; list = service.getBrands();
          return list;
      }
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      @Path(&quot;/{brandId}&quot;)
      public BrandEntity getBrand(int brandId) {
          return service.getBrand(brandId);
      }
      
      @POST
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public Response postBrands(BrandEntity brand ,@Context UriInfo uri ) {
           URI location = uri.getAbsolutePath();
          service.addBrand(brand);
          return Response.created(location).entity(brand).build();
                  //.status(Status.CREATED).entity(brand).build();
      }
  
      @PUT
      @Path(&quot;/{brandId}&quot;)
      @Consumes(MediaType.APPLICATION_JSON)
      public void putBrands(@PathParam(&quot;brandId&quot;) int brandId, BrandEntity updatedBrand) {
          updatedBrand.setBrandId(brandId);
          service.updateBrand(updatedBrand);
      }
  
      @DELETE
      @Path(&quot;/{brandId}&quot;)
      public void deleteBrands(@PathParam(&quot;brandId&quot;) int brandId) {
          service.deleteBrand(brandId);
      }
  
      public Products productDelegation() {
          return new Products();
      }
  }
  This is my BrandService.java file (Service layer)
  
  package shrikant.restapp.showroon.services;
  
  import java.util.List;
  
  import shrikant.restapp.showroon.hibernate.DAO.BrandsDAO;
  import shrikant.restapp.showroon.hibernate.entities.BrandEntity;
  
  public class BrandsService {
  
      BrandsDAO DAO = new BrandsDAO();
  
      public List&lt;BrandEntity&gt; getBrands() {
          List&lt;BrandEntity&gt; list = DAO.getBrands();
          return list;
      }
  
      public void addBrand(BrandEntity brand) {
          DAO.addBrand(brand);
      }
  
      public void updateBrand(BrandEntity updatedBrand) {
          DAO.updateBrand(updatedBrand);
      }
  
      public void deleteBrand(int brandId) {
          DAO.deleteBrand(brandId);
      }
  
      public BrandEntity getBrand(int brandId) {
          return DAO.getBrand(brandId);
      }
  }
  </code></pre>
  <p>this is my BrandsDAO.java file (DAO Layer)</p>
  <pre><code>package shrikant.restapp.showroon.hibernate.DAO;
  
  import java.util.List;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  
  import shrikant.restapp.showroon.hibernate.entities.BrandEntity;
  
  public class BrandsDAO {
  
      SessionFactory factory = new Configuration().configure(&quot;hibernate.cfg.xml&quot;).addAnnotatedClass(BrandEntity.class)
              .buildSessionFactory();
  
      public List&lt;BrandEntity&gt; getBrands() {
          Session session = factory.getCurrentSession();
          session.beginTransaction();
          List&lt;BrandEntity&gt; list = session.createQuery(&quot;from brands&quot;).getResultList();
          return list;
      }
  
      public BrandEntity getBrand(int brandId) {
          Session session = factory.getCurrentSession();
          session.beginTransaction();
          return session.get(BrandEntity.class, brandId);
      }
  
      public void addBrand(BrandEntity brand) {
          Session session = factory.getCurrentSession();
          session.beginTransaction();
          session.save(brand);
          session.getTransaction().commit();
      }
  
      public void updateBrand(BrandEntity updatedBrand) {
          Session session = factory.getCurrentSession();
          session.beginTransaction();
          int id = updatedBrand.getBrandId();
          BrandEntity brand = session.get(BrandEntity.class, id);
          // brand = updatedBrand;
          brand.setBrandName(updatedBrand.getBrandName());
          session.getTransaction().commit();
      }
  
      public void deleteBrand(int brandId) {
          Session session = factory.getCurrentSession();
          session.beginTransaction();
          BrandEntity brand = session.get(BrandEntity.class, brandId);
          session.delete(brand);
          session.getTransaction().commit();
      }
  
  }
  </code></pre>
  <p>this is my entity class</p>
  <pre><code>package shrikant.restapp.showroon.hibernate.entities;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  
  @Entity(name=&quot;brands&quot;)
  @Table(name=&quot;brands&quot;)
  public class BrandEntity {
      
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name=&quot;brand_id&quot;)
      int brandId;
      
      @Column(name=&quot;brand_name&quot;)
      String brandName;
  
      public BrandEntity() {
      }
  
      public BrandEntity(int brandId, String brandName) {
          super();
          this.brandId = brandId;
          this.brandName = brandName;
      }
  
      public int getBrandId() {
          return brandId;
      }
  
      public void setBrandId(int brandId) {
          this.brandId = brandId;
      }
  
      public String getBrandName() {
          return brandName;
      }
  
      public void setBrandName(String brandName) {
          this.brandName = brandName;
      }
  
  }
  </code></pre>
  <p>this is my pom.xml file</p>
  <pre><code>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;shrikant&lt;/groupId&gt;
      &lt;artifactId&gt;restapp&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;restapp&lt;/name&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;restapp&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5.1&lt;/version&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
              &lt;!-- use the following artifactId if you don't need servlet 2.x compatibility --&gt;
              &lt;!-- artifactId&gt;jersey-container-servlet&lt;/artifactId --&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.inject&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-hk2&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-media-json-binding&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;4.0.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.3.7.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;8.0.13&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;properties&gt;
          &lt;jersey.version&gt;2.26&lt;/jersey.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  <p>I don't understand whats the problem anyone help.</p>
  <p><a href="https://i.stack.imgur.com/ZtyLy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZtyLy.png" alt="enter image description here" /></a></p>