Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Cache.evict() after persist, or how?

Setting the reference is the best way to resolve this.

However, it is also possible to have an insert/transaction not update the
shared cache.  To do this you just need to call flush() and then clear()
before commit().  Then the inserted objects will not be added to the shared
cache.  This is sometimes useful for large batch insertions.

Also, BTW, to disable the cache set shared=false do not set type=NONE.

Frank Schwarz wrote:
> The shared cache is some sort of object cache - i.e. it cares about object
> relationships and does not care about foreign keys. If you only maintain
> the foreign keys in your object model - and not the object associations
> itself - you will eventually "corrupt" the shared cache.
> If you do not want to set the real group for performance reasons, you
> could create and set a "mock-up"-instance:
> aLazyGroupInstance = em.getReference(Group.class, groupId);
> When mapping a column twice, it is also considered a good practice to
> declare the foreign key accessor as read-only (-> insertable=false,
> updatable=false).
> -- Frank
> Bálint Kriván wrote:
>> Hello to the community!
>> My question would be the following: I have 2 entites (Many-to-one) When I
>> make a new entity on the left side of the relation and setting the id for
>> the other side (e.g.: user.setGroupId(..);) and persisting this new
>> entity,
>> everything looks fine. But I've realized that EclipseLink caches this
>> entity
>> and when I'm querying all of the entities from this table (e.g.: SELECT u
>> FROM User u) with a JOIN FETCH hint for Group i'm getting null for
>> user.getGroup(); but not for user.getGroupId(); for this newly inserted
>> user. How can I make EclipseLink to forget that I've didn't set the group
>> attribute but the groupId, and ask it to fetch the group entity aswell?
>> (If I'm adding @Cache(type = CacheType.NONE) then it's working, but I do
>> want to use cache, but not for newly inserted entites)
>> What am I doing wrong? Thanks!
>> -- 
>> Regards,
>> Bálint Kriván

----- James Sutherland
 EclipseLink ,
Wiki: EclipseLink , TopLink 
Forums: TopLink , EclipseLink 
Book: Java Persistence 
Blog: Java Persistence
View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top