EntityManager.clear()

In a managed, transactional environment, the persistence context is cleared
at the end of each transaction.  But, in a JSE mode, the persistence
context is still active at the end of a transasction.  EM.clear() will
clear the persistence context.  As long as you don't have any other
references to these entities, they should get cleaned up by the gc.

Is this what you were looking for?

Kevin

On Tue, Jan 8, 2013 at 9:29 AM, Chris Wolf <cwolf.a...@gmail.com> wrote:

> I have a model with, say, a one-to-many relationship, where there may
> be an enormous number of child records.  I see that there is thorough
> documentation treatment on the subject of reading such object FROM the
> database, e.g. fetch=FetchType.LAZY attr and/or @LRS (large result
> set), etc.  but this seems to only optimize READING.
>
> My concern is how can I achieve a similar, converse, optimization when
> WRITING?  i.e. inserting INTO the database.  For example, as I
> understand it, once I persist the master object, (enhanced, of
> course), then the collection field which keeps a set of child records
> uses transitive persistence to automatically write a child record
> whenever a child object is added to the collection - but here's the
> thing; if I'm just doing an initial load of the master object and all
> it's children, and there could be a million children - I don't want
> each newly added child to stay around in memory (in the master's
> collection field) once it has been persisted via transitive
> persistence, otherwise I'll run out of memory.
>
> Is there some mechanism to have child objects be removed from memory
> once persisted?
>
> Thanks,
>
> Chris
>

Reply via email to