How to save only one entity and not its associated entities?

Business scenario:
I want to save data to another database schema when the data is deleted, I use listeners.
When I insert the data into another database, hibernate tells me that no associated entity exists.

For example, in the main database, the user id is 1 and the associated role id is also 1. When user 1 is deleted, saving user 1 to another empty database will report an error. How can I save only the user and not the role?

I don’t know how your code looks like, but usually by setting the role association to null in your code.

I have 2 data sources and 2 entitymanager, one needs to associate role and one doesn’t

Then copy the object. I don’t understand the problem here.

Can it be implemented using the same entity? because they are just in different data sources and everything else is the same

Well, it’s programming, so I guess you can make it work somehow, but I wouldn’t recommend you that, especially because the same entity object should not be attached to two different entity managers. There are some checks for this scenario, but you will see that when you try it.

I use one data source and another data source that only does insert operations to back up the data.
Can it be handled programmatically, I can’t get it working right now

Or is there a way for hibernate to generate a single table insert statement without any association?

I don’t know what else to tell you. You have one entity object and that can only be associated with one entity manager at a time. If you want to persist the same object with two entity managers you will have to flush and clear the first entity manager before persisting it in the other.
If you want to ignore some of the data in the second persist, you will have to alter the object or use some special orm.xml mapping for the second persistence unit.

Well, it seems that it is better to use other methods, thank you very much for your answer