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?

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
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://old.nabble.com/Cache.evict%28%29-after-persist%2C-or-how--tp30211338p30213135.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top