You have to use unowned relationships and not place the department and
the user in the same entity group. See:
http://code.google.com/intl/de-DE/appengine/docs/java/datastore/relationships.html#Unowned_Relationships
use for UserDepartment:
private Set<Key> users = new HashSet<Key>();
and for User:
private Key userDepartmentKey;

Entity groups cannot be changed once being established.
If you want the relationships like you have them, you would have to
change the Key of the User object (it's identity) to place it in the
entity group of another department, since the department's (parent)
key is part of the user key like in a path.

Cheers,
Fred

On 3 Aug., 15:09, Vikas Hazrati <[email protected]> wrote:
> Oops I somehow managed to hit the submit without the full question...
> Apologies...Let me start again
>
> I have 2 entities UserDepartment and User, which are defined as
> follows
> @Entity
> public class UserDepartment extends DomainObject<Long,
> UserDepartment>
> {
>         @Id
>         @GeneratedValue(strategy = GenerationType.IDENTITY)
>         private Long departmentId;
>         @OneToMany(mappedBy = "userDepartment", cascade =
> CascadeType.ALL, fetch=FetchType.EAGER)
>         private Set<User> users = new HashSet<User>();
>
> and
>
> @Entity
> public class User extends DomainObject<Long, User> {
>         @Id
>         @GeneratedValue(strategy = GenerationType.IDENTITY)
>         @Extension(vendorName = "datanucleus", key = "gae.encoded-pk",
> value = "true")
>         private String encodedKey;
>         @Extension(vendorName = "datanucleus", key = "gae.pk-id",
> value = "true")
>         private Long userId;
>         private String username;
>         @ManyToOne(fetch = FetchType.EAGER)
>         private UserDepartment userDepartment;
>
> As you would notice that UserDepartment is the parent of the User. Now
> once I persist the entity group, i want to modify the user so that it
> belongs to a different department now.
>
> What is the best way to do that?
>
> If i remove the UserDepartment from the User and then assign a new
> UserDepartment to it then I get into the issue of trying to access
> multiple entity groups in the same transaction.
>
> Regards | Vikaswww.inphina.com
>
> On Aug 3, 6:05 pm, Vikas Hazrati <[email protected]> wrote:
>
> > I have 2 entities UserDepartment and User, which are defined as
> > follows
>
> > @Entity
> > public class UserDepartment extends DomainObject<Long, UserDepartment>
> > {
>
> >         @Id
> >         @GeneratedValue(strategy = GenerationType.IDENTITY)
> >         private Long departmentId;
>
> > and
>
> > @Entity
> > public class User extends DomainObject<Long, User> {
>
> >         @Id
> >         @GeneratedValue(strategy = GenerationType.IDENTITY)
> >         @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value
> > = "true")
> >         private String encodedKey;
>
> >         @Extension(vendorName = "datanucleus", key = "gae.pk-id", value =
> > "true")
> >         private Long userId;
>
> >         private String username;
> > @ManyToOne(fetch = FetchType.EAGER)
> >         private UserDepartment userDepartment;

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to