First of all, this identity thing is a requirement by JPA and Spring Data JPA uses the JPA APIs of Hibernate behind the scenes. If you don’t like that and would rather want to work with fully detached objects, I would suggest you either use the StatelessSession API of Hibernate, or you save and flush objects one by one, and in between, clear the persistence context.
But ask yourself, what should Hibernate do in this case? You have two distinct objects that refer to the same row in TableB. What if one object has different state than the other? Which state should be written to the database? Which object should be returned by Hibernate when you ask it to find the TableB entity for that identifier?
See how this leads to all kinds of questions that have really no good answer?
But I think there is something else going on here. Do you really need to flush changes to TableB rows when saving TableA rows? Or are you just referring to those objects by the foreign key?
If you are just referring to those objects, you should obtain a reference to a managed object by primary key through tableBRepo.getOne("idB1") and set that object (Hibernate will take care of deduplication) for the association in a TableA entity.
When you really need to save TableB rows alongside, you should think about the first few questions and then you will naturally find a solution where you will have to deduplicate data yourself and in code explicitly decide which TableB data you want to save.
Hibernate is stateful by default, and manages a persistence context composed of managed entities. This means that if you do a change to one object that is part of the persistence context, Hibernate will be able to flush the change without you having to tell Hibernate that it needs to flush the object.
When you call EntityManager.find, Hibernate has to serve objects from the persistence context, and only if that doesn’t contain the object, put the object read from the database into the persistence context. So there may only be one managed entity object in a persistence context for a row with a certain primary key.
This in turn implies that you also can’t association two distinct objects referring to the same row. What if you alter the object which wasn’t put into the persistence context?
Having multiple objects for the same row simply doesn’t work. There are lots of cases which might not apply to your particular case, but are problematic in general, hence Hibernate doesn’t support it.