Overwriting data on submit error

I’ve been over the docs and don’t know how to fix the issue I’ve encountered. I’ve written an app that helps load video games into an online store inventory.

The user fills in a couple of fields of data and clicks to preview the game object. I then make two separate API calls to grab pricing, imagery and descriptions to update the object. Once the user saves it, I send the updated object out to a third API - the store inventory and save it in my postgres database.

Right now, if the user does not refresh the page between submissions, the previous game object is overwritten in the database. I’m sure this is due to how I handle the bean with a mix of form data and generated data.

How do I clear a form and prepare it to receive a new video game? I’ve tried setting the bean to null and clearing the forms fields, but that’s not working.

Edited to add - when the overwrite happens, I see optimistic locking errors in the logs.

Depending on how you use the Binder can readBean or setBean with null

Thanks. Will setting bean with null mean writing the NEXT row in the database instead of rewriting the same row again? I was getting null pointer errors when I did this, but I can try to clean those up

Clean means resetting the form

Tried both suggestions. It’s still overwriting the previous row in the database. How do I reset the form?

It’s my first app and I based it off the form used to update a grid in the tutorial. Maybe that’s where I went wrong. Code is attached for the form and object. I really appreciate any suggestions on what to review or how to learn from this.
VideoGame.java (19.7 KB)

You are mixing the Binder concepts

binder.readBean(videoGame); //grab data
binder.setBean(videoGame); //set the bean with video game data. required for saving to database.

Only use on of these. Please read the docs Loading & Saving to Business Objects | Data Binding | Vaadin Docs

Ok, gives me a place to start. Thanks again for helping out a new dev

Just wanted to post the obvious concept I missed in case there are others who find this. I did clean up my binder as suggested and switched to manually updating the bean in my code. Thanks Simon!

But to get a new row in the database instead of overwriting the old one, I needed to set the bean to a new object. That’s the first step of prepping my form for fresh data entry.