Adding post and then fetching doesn't work in spring
i have test like this(https://github.com/KoblizekXD/notecz-backend/blob/e13d507e7f6bcb738a4ff69bb6d7ded68797d312/src/test/java/lol/koblizek/notecz/api/user/UserControllerTests.java#L40>
but no matterr what i try, the result is always 0 sized, any idea why?
GitHub
notecz-backend/src/test/java/lol/koblizek/notecz/api/user/UserContr...
Contribute to KoblizekXD/notecz-backend development by creating an account on GitHub.
38 Replies
⌛
This post has been reserved for your question.
Hey @Koblížkáč! 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 closed after 300 minutes of inactivity.
Did you try debugging the controller?
💤
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.
yeah
it will get saved)
but findUserById returns user with 0 sized posts
for some reason
Can you try findAll()?
where exactly?
Can you show your repository?
GitHub
notecz-backend/src/main/java/lol/koblizek/notecz/api/user/post/Post...
Contribute to KoblizekXD/notecz-backend development by creating an account on GitHub.
that should contain a
findAll()
method
Can you try calling thatIn your /posts
endpoint, can you call that and print the result?yeah it extends JpaRepository, should i just run it on debugger?
where though
oh
yeah or using a debugger works as well
right
i get
like this
i was wondering if maybe it could be by the configuration of the posts column?
is
user
the correct user?
How are you inserting it?
Can you show the other side of the 1:n relation?like this
post side of the relation is:
in here, is
user
the user with ID 1?yeah
you can see
posts.size = 0
for some reason
yeah ithink why
the order of saving is wrong
inside addpost
any idea how to do it properly?
try that:
maybe switch the last two lines
nope smh
still empty array
Does both happen in the same thread?
well im not doing any parallel stuff, soo how can i check?
actually I think this shouldn't matter since you get a symptom of it being changed
ohhhhhh
i mean it should work
lol
hm?
try using a
List
instead of a Set
or make sure Post#hashCode
and Post#equals
don't include the ID
or do user.setPosts(new HashSet<>(user.getPosts()));
before saving the userokay
but if you want to avoid difficulties, don't persist
Set
s with JPAokay
Does that work?
uno momento
nope
im clueless at this point lol
Can you show your code?
💤
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.