got a bug where when i checkout the 2nd item gets deleted from the order

the weird thing is that the 3 and 4 item are getting added using springboot angular and postgres for fullstack
53 Replies
JavaBot
JavaBotβ€’12mo ago
βŒ› This post has been reserved for your question.
Hey @timo! Please use /close or the Close 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.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Timo
TimoOPβ€’12mo ago
No description
No description
No description
No description
No description
Timo
TimoOPβ€’12mo ago
so the picture is the gui and first you have the price in order wich is 1978 but when you press checkout the 2nd item will be deleted so 1978 - 380= 1598 see picture on the left top 2 the left bottom pic is my controller in springboot and handle it with a delete mapping wich continues with dao dto and model 3 the picture in the middle is my cart.component.ts wich i wrote the functions and also have a cart.service.ts can but the src of the backend in zip but dunno if you guys like that @dan1st | Daniel what do you think?
dan1st
dan1stβ€’12mo ago
I cannot tell you anything about the TS code and images of code are hard to read but it's probably an issue with your backend code, try debugging that idk what endpoint is being called lol
Timo
TimoOPβ€’12mo ago
it goes threw the cartcomponent then to order dto and ordermodel also tried debugging but didn t get much further πŸ˜…
dan1st
dan1stβ€’12mo ago
there's no need to tell me about TS/angular stuff lol
Timo
TimoOPβ€’12mo ago
huh this is springboot
dan1st
dan1stβ€’12mo ago
what happens in the backend? ah ok
Timo
TimoOPβ€’12mo ago
what partπŸ˜‚ quite a lot happens
dan1st
dan1stβ€’12mo ago
First check which endpoints are actually called
Timo
TimoOPβ€’12mo ago
@deleteMapping is being called
dan1st
dan1stβ€’12mo ago
then check whether each of them is doing what it's supposed to/which results in something happing you don't want deleteById?
Timo
TimoOPβ€’12mo ago
correct came with debugging on the delete request
dan1st
dan1stβ€’12mo ago
what does the corresponding service do? So before the delete request, you have 2 entries and after it, you have no entry?
Timo
TimoOPβ€’12mo ago
before the delete request i have 2 datbases with data 1 shoppingcart 2 order shopping cart will be empty after chekout and order will only be cleaned if 1 item gets deleted but after the checout it should stay the same
dan1st
dan1stβ€’12mo ago
what should stay the same? What is deleted? What should be deleted?
Timo
TimoOPβ€’12mo ago
right bottom is the order once checout get s pressed that should stay and cart_components should delete all cuz when you checkout/pay you don t want any items in your shoppingcart
dan1st
dan1stβ€’12mo ago
so the order shouldn't be removed? maybe it's because of a ON DELETE CASCADE?
Timo
TimoOPβ€’12mo ago
could be ig the order shouldn t be removed only the cart doesn t make much sense to me tho XD
dan1st
dan1stβ€’12mo ago
Can you share the code of the relevant service? Does the order table reference the card table?
Timo
TimoOPβ€’12mo ago
can i sent the zip or is that not allowed for security reasons?
dan1st
dan1stβ€’12mo ago
I can't really read ZIPs on my mobile properly anyways just send the relevant code using the codeblock or even better, a minimal, complete and verifiable example
Timo
TimoOPβ€’12mo ago
but not sure what to sent cuz got controller dao dto repo and model cuz just sent it as txt but not sure what to even sent
dan1st
dan1stβ€’12mo ago
As I said, the service deleteOrderCartComponentBycartitemid
Timo
TimoOPβ€’12mo ago
Timo
TimoOPβ€’12mo ago
this? πŸ™ƒ
dan1st
dan1stβ€’12mo ago
Can you also show the order entity?
Timo
TimoOPβ€’12mo ago
what do you mean by entity?
dan1st
dan1stβ€’12mo ago
the @Entity class CartComponents
Timo
TimoOPβ€’12mo ago
you mean the ordermodel sorry im confused
dan1st
dan1stβ€’12mo ago
Do you have a class called CartComponents?
Timo
TimoOPβ€’12mo ago
a model yeah
dan1st
dan1stβ€’12mo ago
Can you show it?
Timo
TimoOPβ€’12mo ago
and that has entity within with class
Timo
TimoOPβ€’12mo ago
dan1st
dan1stβ€’12mo ago
@ManyToOne(cascade = CascadeType.MERGE)
//@JoinColumn(name = "orders_id")
@JsonBackReference

private Order order;
@ManyToOne(cascade = CascadeType.MERGE)
//@JoinColumn(name = "orders_id")
@JsonBackReference

private Order order;
Removing the cascade = CascadeType.MERGE doesn't help, right?
Timo
TimoOPβ€’12mo ago
dunno have it in those 3 but maybe im stupid but why are we looking in the model of cart when the problem is with the orderdatabse?
No description
dan1st
dan1stβ€’12mo ago
I wanted to make sure that deleting the card doesn't delete the order actually can you also show your order model?
Timo
TimoOPβ€’12mo ago
Timo
TimoOPβ€’12mo ago
seems to me to cart gets first then order and order gets called once and is 2nd or something and that is why the 2nd item is deleted and the rest is fine but not sure
dan1st
dan1stβ€’12mo ago
Can you check the following? Before calling deleteOrderCartComponentsBycartimtemId, the order is there in the DB - after calling that, the DB entry for the order disappears (which you don't want) - There are no other requests handled while that happens Also you could try enabling logging of SQL statements to find out what deletes it
Timo
TimoOPβ€’12mo ago
when debugging and pressing checkout i came out on that delete thing so think that is the only request running in that action don t know logging on sql statements getting kinda tired tho so thnaks a lot for your help but dunno how much longer i can be sharp pretty late in europeπŸ˜…
dan1st
dan1stβ€’12mo ago
I live in Austria so same
Timo
TimoOPβ€’12mo ago
nice i have worked as a skiteacher in austria πŸ™‚
dan1st
dan1stβ€’12mo ago
Stack Overflow
How can I log SQL statements in Spring Boot?
I want to log SQL statements to a file. I have the following properties in application.properties: spring.datasource.url=... spring.datasource.username=user spring.datasource.password=1234 spring.
Timo
TimoOPβ€’12mo ago
added it then i should rerun my backend and what should be different then?
dan1st
dan1stβ€’12mo ago
it would print all SQL statements it's executing to the console
Timo
TimoOPβ€’12mo ago
so kinda a debugging tool for sql?
dan1st
dan1stβ€’12mo ago
kinda the idea is that it should also include the statement that's deleting the thing
Timo
TimoOPβ€’12mo ago
good to know do you mind i will continue tomorrow cuz feel kinda braindead rn sorry
dan1st
dan1stβ€’12mo ago
πŸ‘
JavaBot
JavaBotβ€’12mo ago
πŸ’€ 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.

Did you find this page helpful?