How to query JDO persistent objects in unowned relationship model?
Posted
by Paul B
on Stack Overflow
See other posts from Stack Overflow
or by Paul B
Published on 2010-06-14T13:12:12Z
Indexed on
2010/06/14
17:12 UTC
Read the original article
Hit count: 328
Hello,
I'm trying to migrate my app from PHP and RDBMS (MySQL) to Google App Engine and have a hard time figuring out data model and relationships in JDO. In my current app I use a lot of JOIN queries like:
SELECT users.name, comments.comment
FROM users, comments
WHERE users.user_id = comments.user_id
AND users.email = '[email protected]'
As I understand, JOIN queries are not supported in this way so the only(?) way to store data is using unowned relationships and "foreign" keys. There is a documentation regarding that, but no useful examples. So far I have something like this:
@PersistenceCapable
public class Users {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String name;
@Persistent
private String email;
@Persistent
private Set<Key> commentKeys;
// Accessors...
}
@PersistenceCapable
public class Comments {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String comment;
@Persistent
private Date commentDate;
@Persistent
private Key userKey;
// Accessors...
}
So, how do I get a list with commenter's name, comment and date in one query? I see how I probably could get away with 3 queries but that seems wrong and would create unnecessary overhead. Please, help me out with some code examples.
-- Paul.
© Stack Overflow or respective owner