views:

60

answers:

2

My understanding is that with GAE JPA support I cannot:

@ManyToMany
    private Set<SSUser> contacts; 

    protected SSUser(){}

    public SSUser(final String userId, final String emailId){
        this.userId = userId;
        this.emailId = emailId;
        contacts = new HashSet<SSUser>();
    }

I'm trying to establish a contacts relationship. Did I correctly understand that the above is not allowed?

If so, would Set<String> contactsIds be allowed? Could I be provided a working example?

A: 

From the online documentation about what the datastore doesn't support:

Unsupported Features of JPA

The following features of the JPA interface are not supported by the App Engine implementation:

  • Owned many-to-many relationships, and unowned relationships. You can implement unowned relationships using explicit Key values, though type checking is not enforced in the API.
  • "Join" queries. You cannot use a field of a child entity in a filter when performing a query on the parent kind. Note that you can test the parent's relationship field directly in query using a key.
  • Aggregation queries (group by, having, sum, avg, max, min)
  • Polymorphic queries. You cannot perform a query of a class to get instances of a subclass. Each class is represented by a separate entity kind in the datastore.
Pascal Thivent
it's exactly after reading that that i posted!How else would you implement this very basic relationship in GAE still using JPA? Set<String> contactsUsrIds? Nothing better?
simpatico
@simpatico: The GAE workaround is to map `Key` collections, see http://code.google.com/appengine/docs/java/datastore/relationships.html#Unowned_Relationships. This reference is for JDO but my understanding is that you can transpose the concepts to JPA (sadly, the JPA documentation sucks big time, it's like Google doesn't want you to use JPA).
Pascal Thivent
I'm having the same feeling! Is there a GAE JPA demo/example?
simpatico
Google wants you to use JDO because JPA was designed with relational (SQL) databases in mind. App Engine's datastore is NOT a SQL database. From wikipedia: 'The Java Persistence API specifies relational persistence (ORM: Object relational mapping) only for RDBMS (although providers exists who support other datastores). The Java Data Objects specification(s) provides relational persistence (ORM), as well as persistence to other types of datastores.'
Peter Recore
Yes, but I don't know JDO, and my needs a really limited. I just need to maintain a contacts database. I.e. google account user A is a contact of B.
simpatico
@Peter I'm well aware of what JDO and JPA are for. And regardless of the posted links, Google **is** offering JPA support for their datastore so they should either document it properly or drop it if JPA is not appropriate, not some bastard thing in between that looks like weak marketing.
Pascal Thivent
@Pascal Thivent I agree that it is lame to list JPA as supported but not have great docs for it. Maybe they need to say JPA support is "pre-beta" or something that better describes its state as a second class citizen. On a positive note, there are some good tidbits, in both JPA and JDO here: http://googleappengine.blogspot.com/2009/12/jpajdo-java-persistence-tips-year-in.html
Peter Recore
@Peter Thanks for the link, good stuff.
Pascal Thivent
It turns out that helloorm in the bundled demos is a jpa example too.
simpatico
A: 

Yes, they are not allowed.

Set contactsIds be allowed? Could I be provided a working example?

It works, see: http://screenshoter.svn.sourceforge.net/viewvc/screenshoter/screenshoter/trunk/SS-server/src/com/mysimpatico/ss/server/SS_serverServlet.java?revision=8&amp;view=markup

simpatico