• Post Reply Bookmark Topic Watch Topic
  • New Topic

creating first rest service  RSS feed

 
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create my first restservice but came across a weird error: I'm trying to surch for a string but somehow it expects a number could anyone try to explain to me why?

This is the error:

As you can see the query is being executed, so I guess that means the controller works

 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's most likely not the request, but the response tha causes the error? An other question, can I use spaces in my request?
 
Rancher
Posts: 3497
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show your service?
And the request made.

This seems to be an issue with mapping the request to the given objects/attributes.
 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request was simply maded in the browser

The controller:

 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should mention I'm using JpaRepostories, so no implementations
 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I execute a request to search by author, I get no error, but nop response eather, just a blank page
 
Dave Tolls
Rancher
Posts: 3497
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the request URL?

Also, is the "findBooksByTitle" String anywhere in your code, or xml/properties/whatever other than as that method name (do a search)?
 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the request url is http://localhost:8090/books/search/title/name of title. findBookByTitle isn't the name of the controllermethod, it's the name of my JpaRepositorymethod
 
Dave Tolls
Rancher
Posts: 3497
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but that's the text that Spring is complaining about, so it must be coming in from somewhere.
That's why I suggest searching for it.

Failing that, try and debug the Spring code.
you should be able to stick a breakpoint somewhere in there.
That might give you a chance to spot where this text is coming from.
 
Saloon Keeper
Posts: 1613
56
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:the request url is http://localhost:8090/books/search/title/name


Shouldn't this line be for the above line to work?
Please note the addition of the "/" before {tittle}.
 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Pete: that's actualy a typo, but shouldn't really mather

@Dave: He complains that he can't convert a string to a long, so it must be while he's trying to parse the id, it's the only thing that's a long, it still weird I have a standalone javafxapp that uses the same data and no probs there
 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changing the typo took care of the errormessage, but I stiil dont get the response entity, just a black page
 
Pete Letkeman
Saloon Keeper
Posts: 1613
56
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I stiil dont get the response entity, just a black page


If you do a "view page source" in your web browser do you see data? There is a chance that you have incorrectly formed HTML tags.

I think that in using a log tool/Logger you could see if the JpaRepositorymethod that you are using is returning data before merging the result with the template.
Maybe the data that you expect is there in the database is not there according to JpaRepositorymethod.
 
Daniel Demesmaecker
Rancher
Posts: 285
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
black page, should have bin blankpage. I'm also using jpaRepo's in my fxprogram, and there it works fine. When executing with postman I get an error that no responce returned
 
Pete Letkeman
Saloon Keeper
Posts: 1613
56
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. Unfortunately I've only just begun my journey in learning Spring and I'll admit that I don't know that much regarding it.
I know that I got lucky in spotting the cause of the initial issue.

Are you able to provide the following information:
  • I suspect that you are using Spring, but you could be using Spring Boot. Please clarify.
  • Which version of Spring or Spring Boot are you using?
  • While you are using the JPA Repos to help with data operations, it may be helpful to know what your database back end actually is (MySQL, MongoDB etc) and what version of that you are using.

  • Hopefully someone who have is more knowledgeable with Spring can help you out even more.
     
    Daniel Demesmaecker
    Rancher
    Posts: 285
    6
    Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm using spring boot 4.2 and mysqldatabase not sure of the version, it's a testdb from db4free.net, I think 8
    Using mysqlconnector 5.44 and a tomcat8 server
     
    Ranch Hand
    Posts: 36
    Java Mac OS X Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Pete Letkeman wrote:Please note the addition of the "/" before {tittle}.


    Good catch Pete.

    Daniel Demesmaecker wrote:changing the typo took care of the errormessage, but I stiil dont get the response entity, just a black page



    Which browser you are using?
    I am assuming that you are using Chrome, if so then please follow the steps given below and check the response.

    - Press F12 (Windows) or CMD+OPTION+I (Mac) which will open the developer's console on your browser.
    - Click on 'Network' and clear the requests already present there by clicking on clear sign
    - Put your URL in browser and hit enter
    - You will see a request now available for you in your developer's console
    - Click on your request and check the response tab to see if you can see the output you were expecting
     
    Daniel Demesmaecker
    Rancher
    Posts: 285
    6
    Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Which browser you are using?
    I am assuming that you are using Chrome, if so then please follow the steps given below and check the response.


    Not that's it's important, but I'm using firefox and no, I'm not getting the expected response.
    However I update my code, so I would let me know if I get a result from the db and apperently I don't
     
    Daniel Demesmaecker
    Rancher
    Posts: 285
    6
    Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm getting a 204, and since the list is empty, I guess this is the expected response
     
    Ankur R Jain
    Ranch Hand
    Posts: 36
    Java Mac OS X Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Daniel Demesmaecker wrote:I'm getting a 204, and since the list is empty, I guess this is the expected response



    If your list is empty, you should get something like this as response - []

    By the way, you should change the configuration to have hibernate.show_sql=true and check the query which is getting executed to the database, that way you will be able to identify why you are not getting any output.
     
    Daniel Demesmaecker
    Rancher
    Posts: 285
    6
    Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you go to the stacktrace from my originalpost, you can see the query is shown...
     
    Daniel Demesmaecker
    Rancher
    Posts: 285
    6
    Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I managed to figure out what was the problem, I could shoot myself so obvious. For those interested, I'll post the answer.
    I told you guys earlier that I was using the same db for my javafx program, in fact the db is created using that program.
    In that program my entity is called book, while my dbtable is called books.
    In my rest service my entity is called book, but I didn't specify an other name for the table.
    So instead of searching in the table books, hibernate created a new table book and was using this table.
    Since the table had no data I got empty results from all my queries.
    Changing the entityname solved the problem.
     
    If you're gonna buy things, buy this thing and I get a fat kickback:
    Rocket Oven Kickstarter - from the trailboss
    https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!