java - How one to many relationship gets persisted in JPA if i have thousands of related entities already in data base and i add new entities in collection -


we have 2 entities entity1 , entity2, entity1 contains set of entity2, have thousands of entities stored in database of entity type entity2 referenced instance of entity1, myentity.

now if add more entity2 entities collection , try persist myentity, newly added entities of entity2 persisted.

my question how behavior on persist of myentity , whether existing members of relation travel memory , new members added or new members added database without bringing existing members memory

if have thousands of referenced entities, might better not map relationship , instead query when needed - allowing use paging or other mechanisms reduce amount of entities read in @ time. depends on type of mapping is, owning relationship needs mapped (the 1 doesn't have mapped by) set foreign key in database. set entity2 side owning side if isn't already.

if m:m relation table , doesn't make sense map entity2 side instead - add entity relation table read in same way. new entity have reference entity1, entity1 wouldn't reference it, , app query new entity when needs entity2s associated specific entity1.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -