• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Delete a JPA entity in a Scheduled Task

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good Morning. I'm doing a rest API for an app, and I need that whenever from 00h the user data stored in a List<> be deleted. This list lists OneToMany data.

I have 2 entities, the parent entity (DayUser) and the child entity (FoodConsumed).


Child Entity:


I use this repository for the child entity:



The problem is the following, when I try to delete the data by the id in a task they just change the id and continue in the database. But when I try to DELETE a API request it works normally.

Scheduled Task (It's not working):


When this task is executed, the items go to a new id and remain related to the DayUser even though I call the repository.deleteByID
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Matheus!

You can get better answers if you reduce your code samples to just the essentials. When you post every last detail some of us won't bother to read any of it because it's too hard to make sense of when your code won't all fit on the screen at once and we can't see the forest for the trees.

And I'm afraid that that's what I'll be doing as well - we're not paid anything to do this, so it's not worth the extra work to decode all that stuff. So I'll do what I usually do in such cases and suggest based on common errors.

In this particular case, I'm suspecting that you may not be flushing your deletion out to the database. Failing to do so can cause confusion if some other user fetches the same data.
 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matheus,
For this piece:

try this:

I guess your food is not found. I can be wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic