Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Inserts and Caching

Are you concerned with caching across transaction or within the same
transaction?

Across transaction you can disable caching using the persistence.xml
property,
"eclipselink.cache.shared.default"="false".  Or you can set the size or type
of the cache to control how many objects are cached.

For avoiding caching within a single transaction, the best way is to flush()
then clear() the EntityManager.  You could do this for each object, or
probably better for each batch of objects.

Also ensure you application does not hold onto the objects, otherwise they
will not be able to gc.



ossaert wrote:
> 
> Hi,
> 
> I have the following design problem. I have in EJB a remote interface
> which actually is a projection of my use-case. This remote method calls
> different local apis.
> 
> Important to know is that the use-case is a unit. Or the method is
> committed or rolled back completely.
> 
> Now, during the execution of this method I have a call to a method which
> insert event-objects into the database. Unfortunately, these event objects
> remain in memory until my transaction commits. Is there a way to avoid
> this (without having to use the SQL INSERT statement directly)? I found in
> EclipseLink the method InsertObjectQuery.
> 
> public void sendEvent(NodeEntity nodeEntity, EventType eventType) {
> 
>         EventEntity event = new EventEntity();
>         event.setNodeGuid(.....);
>         event.setEventType(....);
> 
>         /* This is the EclipseLink specific part */        
>         InsertObjectQuery writeQuery = new InsertObjectQuery();
>         writeQuery.setObject(event);
>         writeQuery.dontMaintainCache();
> 
>         /* Convert the query to JPA query */
>         Query q = JpaHelper.createQuery(writeQuery,
> this.getEntityManager());
>         q.executeUpdate();
> }
> 
> This method, I hope, should be able NOT TO CACHE the EventEntity? So, when
> I have let's say 5000 eventEntities in my method, they will not remain in
> memory and will not cause a heap space problem? 
> 
> Unfortunately, this method does not function within JPA (Glassfish). I get
> the following error:
> Objects cannot be written during a UnitOfWork, they must be registered.
> 
> I tried to register it (using
> entitymanager.getUnitOfWork().registerNewObject() etc), but without
> success.
> 
> Are my assumptions correct and/or is there a method to do insert using the
> API in JPA (so I can refactor it easily) ? Now, as a work-around I use the
> SQL INSERT statement directly, but that is not always portable.
> 
> Actually, I would be nice if you could remove one object from the cache or
> to prevent the object from being cached. Sometimes, you have objects you
> must write to the database use JPA (annotated with @PrePersist etc) which
> you don't need afterwards.
> 
> Does the annotations @Cache(type=CacheType.NONE) actually function when I
> execute the normal "entitymanager.persist(eventEntity)"?
> 
> Greetings
> Jan
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Inserts-and-Caching-tp24109228p24167053.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top