Consider the following scenario where a JPA entity EntityA has a transient field consisting of a list of EntityB entities, where a ManyToOne mapping exists between EntityB and EntityA:
@Entity
class EntityA {
@Id
Long ID;
@Transient
List<EntityB> entityBList;
}
@Entity
class EntityB {
@Id
Long ID;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "entity_a_id")
private EntityA entityA;
}
Suppose we load an EntityA and the corresponding list of entities EntityB from the DB (managed entities) and we set the list to EntityA's transient field, entityBList.
I intend to use the transient field merely as a transfer object. Then I intend to perform write operations with the parent entity (EntityA). Given that the list of entities B is loaded into the persistent context (they become managed), I suppose after saving and flushing the parent entity, EntityA, in case any of the entities B gets "dirty" and despite them being assigned to a transient field, there will be consequences in the DB, right? What are other unintended repercussions of using this "hack"? What could go wrong?