SpringBoot missing certain fields on auto generated repository
Hello,
I have a maven springboot project using an H2 database. I have a module class with three fields; name, code and mnc
You can see the first few lines of this class below
As you can see code has a corresponding getter (getCode() method), and with my ModuleRepository interface:
You would expect the "code" variable to be visible when making a REST request. However, no matter what I seem to do, I can only seem to get the following response with two of the three variables.
As well as this, the
code
variable in the database is definitely updated, it just doesn't display in the json response.
Thanks in advance.12 Replies
⌛
This post has been reserved for your question.
Hey @jabbers! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Not sure if it has something to do with
code
being the primary key - but I need the code as a variable in the response
Anyone able to help ?where is the request?
also why do you use code for primary key?
do you have a particular reason to use @Column like specific configurations for the respective column?
why does mnc have a default value of false?
And also for mnc why do you use the wrapper, but in the constructor you pass in a primitive?
try switching the id annotation to some other field and see if that field appears
and yea try renaming the field to something else maybe its a reserved word
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
wdym? its a GET request on /modules
code is a unique value which identifies each row of t he db, if thats what ur asking
uhhh, im not too sure what u meann here. I was just making sure the correct columns were marked as they are in db
because when u attempt to create a new module, the mnc is undefiined in the payload of the request from the frontend if its false. so, if mnc is null, its false, so i set default value to false
i will try it thank you
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
thank you both for ur help ill let u know how i get on
literally just a typo
So, this is interesting - ur suggestion of moving the ID field to the name field actually worked
So for whatever reason it just doesn't wanna show the primary key
maybe some rest config makes it so the field with id annotation isnt included
try to check that
i dont know how i didn't find this earlier, but this explains everything. im able to expose ids for certain classes now https://stackoverflow.com/questions/77273097/json-data-doesn-t-show-the-id-column-when-running-spring-boot-project
Stack Overflow
JSON data doesn’t show the id column when running Spring Boot proje...
I’m working on a Spring Boot project where I have an entity called “Book” with an id column. I’m using Spring Data JPA and have created a repository interface called “BookRepo” that extends JpaRepo...
thank u for ur help 😉
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.