Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] CacheCoordinationType usage

That is odd.  When you find the profile, what is its id, is it valid?  Can't
see how it would be possible for it to be considered a new object.  Are you
finding the profile in the same EntityManager as you persist the User?  Does
your setProfile method somehow create a copy of the Profile?

SEND_NEW_OBJECTS_WITH_CHANGES is not required, using
INVALIDATE_CHANGED_OBJECTS is fine (even recommend).

Also using caching a setting alwaysRefresh to true makes little sense.  If
you always want to access the database, then don't bother caching, set
shared=false instead.



Seckin Yazan wrote:
> 
> Hi;
> I have an application deployed on glassfish cluster environment and doing
> some sort of DB operations, and currently having problem with the
> following case
> 
> There are two classes as follows;
> 
> @Cache(coordinationType =
> CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, type =
> CacheType.FULL, shared = true, size = 100, alwaysRefresh = true)
> public class Users implements Serializable {
>     @Id
>     @Column(name = "USERID", nullable = false, insertable = true,
> updatable = true, length = 100)
>     private String                 userId;
>     @ManyToOne
>     @JoinColumn(name = "ProfileId", referencedColumnName = "ProfileId",
> nullable = true, insertable = true, updatable = true)
>     private Profiles         profile;
> 
> @Cache(coordinationType =
> CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES, type =
> CacheType.FULL, shared = true, size = 100, alwaysRefresh = true)
> public class Profiles implements java.io.Serializable {
> 
>     @Id
>     @Column(name = "ProfileId", nullable = false, insertable = true,
> updatable = true)
>     private int                  profileId;
> 
>     @OneToMany(mappedBy = "Profile")
>     private Collection<Users> profile;
> 
> 
> somewhere inside the code i do the following operations
> //Create a new user
> User user = new User();
> 
> //Set profile which is already in DB for user
> Profile profile =  entityManager.find(Policy.class, id)
> user.setProfile(Profile);
> 
> //Insert user to DB
> entityMan.persist(user);
> 
> right after this operation i get duplicate entry exception for profile,
> because while inserting user to DB it also tries to insert Profile which
> is already exist in DB. If I change
> CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES to
> CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS it works fine. As far as
> i know i need to use SEND_NEW_OBJECTS_WITH_CHANGES in order to inform
> other instances in the cluster for this newly created user object, 
> 
> Any comment?
> 
> Thanks
> 
> Seckin
> 
> 
> 
> 


-----
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/CacheCoordinationType-usage-tp24860637p25045351.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top