First, the version of Java and whether or not you're using Spring Boot do not matter. What you are calling "jpa repository" sounds like Spring JPA, so I'm going to answer according to that.
When you define a one-to-many relationship using JPA (whether it's with Spring or not) then you should also define a many-to-one relationship on your Entity B to point back to its parent. If you don't do this, then not everything may persist properly to the database. Let me use parent-child terms here, since whether A and B are actually parent/child or just organized like they are doesn't matter and so I can use simpler terms.
When you create a new A record and one or more B records, you should not be thinking in terms of SQL. JPA is handling that. Think in Java terms. You create A, and add each B to its child collection property (One-to-Many). As you do so, point the new B back to A using its parent property (Many-to-One). When you are ready to persist to the database, start a transaction, persist each B record, and then persist the A record. Then end the transaction. Your database is now properly updated.
Beyond that, there is one additional thing to be aware of. In JPA, persisting an update to a database may return a new copy of the object being persisted. After you persist, you must use this new object. The original A and B objects are no longer usable. And, in fact, if you attempt to use them, you'll see problems like the one you described.
We have a forum dedicated just for ORM systems like JPA and Hibernate, so I'm moving this thread over there. You should always try to ask questions in the forum that best matches the type of question you are asking. That's where the people who can give the answers are.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad: