[appengine-java] Re: hard time modeling my database

2011-02-08 Thread WillSpecht
So you are worried that a user will be deleted and his key will still
be linked to the book?  You can't rely on the database to do that work
for you.  You can do this two ways, worry about it, and when you
delete a user, make sure you delete it's key from every book.  Or
don't worry about it.  If you do your queries right, having a non
existent user stored in a book won't cause any problems.  But I would
recommend removing it when a user gets deleted.

On Feb 7, 3:11 pm, Arjan arjan.br...@gmail.com wrote:
 Will,
 Thanks for the hint.
 When i use the User key (a String) as the reference from the Book to the
 User object, that would mean that the referential integrity is not enforced
 by the database. I understand that it would work, but it feels kind of
 strange.
 Is there a way to maintain the referential integrity on between the classes?
 Regards.

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: hard time modeling my database

2011-02-07 Thread Arjan
Will,
Thanks for the hint.
When i use the User key (a String) as the reference from the Book to the 
User object, that would mean that the referential integrity is not enforced 
by the database. I understand that it would work, but it feels kind of 
strange.
Is there a way to maintain the referential integrity on between the classes?
Regards.

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.



[appengine-java] Re: hard time modeling my database

2011-02-06 Thread WillSpecht
You want to store the Key of the User not the actual User.  If you
store the User you are creating an owned relationship.  This means
that the user can only be owned by one book.  What you want is an
unowned relationship, which means storing the keys.  Then your query
stays the same except you will need to add query.import(import Key)
--- not the exact syntax

On Feb 6, 5:04 pm, Arjan arjan.br...@gmail.com wrote:
 Hi all,
 It seems like i am doing this the wrong way and the datastore is giving me a
 hard time making queries.
 I've got a my own User class in my application and there is a Book class in
 the application.
 Now the Book class has an owner and a write attribute.
 @Entity
 class User {
   @Id
   private String email;

 }

 @Entity
 class Book {
    @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private Key key;
 private User owner;
 private User writer;

 }

 I want to search the store for all owned books (on the users myPage)
 Query query = getEntityManager().createQuery(SELECT b FROM Book b WHERE
 b.owner == :owner);
 query.setParameter(owner, owner);

 ListBook books = query.getResultList();

 Now the datastore is throwing ugly things to me like Key of parameter value
 does not have a parent.

 I'm realy lost here. Could anyone explain to me how i could solve this?

-- 
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 google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.