Skip to main content

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

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.

Greetings
Jan
-- 
View this message in context: http://www.nabble.com/Inserts-and-Caching-tp24109228p24109228.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top