|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,
> -- 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
>> everything looks fine. But I've realized that EclipseLink caches this
>> 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!
>> Bálint Kriván
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
Blog: http://java-persistence-performance.blogspot.com/ Java Persistence
View this message in context: http://old.nabble.com/Cache.evict%28%29-after-persist%2C-or-how--tp30211338p30238349.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
eclipselink-users mailing list
Back to the top