GAE Datastore

58 views
Skip to first unread message

Almas NURKHOZHAYEV

unread,
Oct 18, 2011, 8:43:23 AM10/18/11
to play-framework
Hello,
I wanna work with GAE and as you know it supports only datastore.
So, I want to make my main database as google datastore.
How can I configure to work with google datastore, but I want to use
all the JPA features of Play!????

waiting for your response,
and my best regards,

christian sarnataro

unread,
Oct 18, 2011, 9:35:26 AM10/18/11
to play-fr...@googlegroups.com
Hi,
simply install GAE modules, JPA is supported (with some limitations from GAE JPA).

see:

Beside gae module, you could try siena or objectify for datastore access, both support gae datastore.

Siena maybe is a little bit more versatile, as it supports also mysql and other rdbms.

Almas NURKHOZHAYEV

unread,
Oct 18, 2011, 10:22:38 AM10/18/11
to play-framework
Thanks you very much!
Play framework embedded GAE test example also supports and has
starting codes.

I thought that I will get an answer not less than a week :)))
Thanks a lot again

On Oct 18, 4:35 pm, christian sarnataro

Pascal Voitot Dev

unread,
Oct 18, 2011, 10:24:51 AM10/18/11
to play-fr...@googlegroups.com
Hi,
I advise you not to use JPA but Objectify or Siena.

Pascal

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


Almas NURKHOZHAYEV

unread,
Oct 18, 2011, 3:28:48 PM10/18/11
to play-framework
Thanks Pascal,
Yeah,
I liked Siena, just tried several examples.
I didn't tried Objectify, I'll have a look for it too.

Thanks again
Almas

On Oct 18, 5:24 pm, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> Hi,
> I advise you not to use JPA but Objectify or Siena.
>
> Pascal
>

Pascal Voitot Dev

unread,
Oct 18, 2011, 3:37:27 PM10/18/11
to play-fr...@googlegroups.com
objectify fits GAE perfectly it's clear and is well written IMO.
Siena is more versatile and provide some unique features but I'm not objective, I'm lead dev of Siena :D

Pascal

Andriy Zhdanov

unread,
Oct 18, 2011, 4:15:13 PM10/18/11
to play-framework
Have you looked at siena module? Also, in the mailing list, I've seen
there is google cloud sql, which might be better.

Almas NURKHOZHAYEV

unread,
Oct 19, 2011, 7:20:50 AM10/19/11
to play-framework
Is there any documentation (or API) for Siena? (for GEA)
I wanna compare with JPA to learn more faster.

Thanks in advance

On Oct 18, 10:37 pm, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> objectify fits GAE perfectly it's clear and is well written IMO.
> Siena is more versatile and provide some unique features but I'm not
> objective, I'm lead dev of Siena :D
>
> Pascal
>

Pascal Voitot Dev

unread,
Oct 19, 2011, 7:37:20 AM10/19/11
to play-fr...@googlegroups.com
Go there: http://www.sienaproject.com/index.html
Then : https://github.com/mandubian/siena/blob/master/source/documentation/manuals/first_model.textile
Then : https://github.com/mandubian/siena/wiki/Manuals
This one is about queries: https://github.com/mandubian/siena/blob/master/source/documentation/manuals/query.textile

after that, we have some special features around aggregation/embedding linked to NoSQL features and the new syntaxes One<T>/Many<T> providing syntactic sugar for One2Many relations.

regards
Pascal

Almas NURKHOZHAYEV

unread,
Oct 19, 2011, 8:47:37 AM10/19/11
to play-framework
Hey guys,
I wanna make the same yabe project but with Siena, I'm now at second
page:
http://www.playframework.org/documentation/1.2.3/guide2
and trying to make a relation with Post and Comment models
I didnt put any @ManyToOne annotations like in example and getting
this error:

useTheCommentsRelation A java.lang.IllegalArgumentException has been
caught, Unsupported type: models.Comment
In /test/BasicTest.java, line 115 :
almasPost.addComment("Jeff", "Nice post");
Hide trace
java.lang.IllegalArgumentException: Unsupported type: models.Comment
at siena.Json.(Json.java:102)
at siena.embed.JsonSerializer.serialize(JsonSerializer.java:103)
at siena.embed.JsonSerializer.serialize(JsonSerializer.java:27)
at siena.embed.JsonSerializer.serialize(JsonSerializer.java:52)
at siena.embed.JsonSerializer.serialize(JsonSerializer.java:27)
at siena.gae.GaeMappingUtils.fillEntity(GaeMappingUtils.java:412)
at
siena.gae.GaePersistenceManager._updateSimple(GaePersistenceManager.java:
556)
at siena.gae.GaePersistenceManager.update(GaePersistenceManager.java:
513)
at siena.Model.update(Model.java:83)
at models.Post.addComment(Post.java:39)
at BasicTest.useTheCommentsRelation(BasicTest.java:115)
......

But in example it says that if I delete Post then system automatically
deletes all Comments related to this Post,
Here is the original JPA example

@OneToMany(mappedBy="post", cascade=CascadeType.ALL)
public List<Comment> comments;

public Post(User author, String title, String content) {
this.comments = new ArrayList<Comment>();
this.author = author;
this.title = title;
this.content = content;
this.postedAt = new Date();
}

public Post addComment(String author, String content) {
Comment newComment = new Comment(this, author, content).save();
this.comments.add(newComment);
this.save();
return this;
}


I'm getting error when I try to add comment to existing post.
Any idea?

Regards,
Almas

On Oct 19, 2:37 pm, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> Go there:http://www.sienaproject.com/index.html
> Then :https://github.com/mandubian/siena/blob/master/source/documentation/m...
> Then :https://github.com/mandubian/siena/wiki/Manuals
> This one is about queries:https://github.com/mandubian/siena/blob/master/source/documentation/m...
>
> after that, we have some special features around aggregation/embedding
> linked to NoSQL features and the new syntaxes One<T>/Many<T> providing
> syntactic sugar for One2Many relations.
>
> regards
> Pascal
>

Pascal Voitot Dev

unread,
Oct 19, 2011, 8:56:27 AM10/19/11
to play-fr...@googlegroups.com
Not sure to understand!
Siena is not JPA, you can't use JPA annotations in Siena!
moreover Siena is inspired by NoSQL features so cascade is not something provided by Siena (neither Join because JOIN doesn't exist in GAE)

You must change your model into siena syntax!

Bakanis had rewritten the Yabe with Siena here:
https://github.com/bakanis/bakanis-yabe-siena/tree/master/app

Pascal

Almas NURKHOZHAYEV

unread,
Oct 19, 2011, 9:03:18 AM10/19/11
to play-framework
Thank you very much Pascal

On Oct 19, 3:56 pm, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> Not sure to understand!
> Siena is not JPA, you can't use JPA annotations in Siena!
> moreover Siena is inspired by NoSQL features so cascade is not something
> provided by Siena (neither Join because JOIN doesn't exist in GAE)
>
> You must change your model into siena syntax!
>
> Bakanis had rewritten the Yabe with Siena here:https://github.com/bakanis/bakanis-yabe-siena/tree/master/app
>
> Pascal
>

Almas NURKHOZHAYEV

unread,
Oct 20, 2011, 3:29:17 AM10/20/11
to play-framework
Is there any possibility in Siena to make such queries like in JPA?

List<Comment> bobComments = Comment.find("post.author.email",
"b...@gmail.com").fetch();

regards

On Oct 19, 3:56 pm, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> Not sure to understand!
> Siena is not JPA, you can't use JPA annotations in Siena!
> moreover Siena is inspired by NoSQL features so cascade is not something
> provided by Siena (neither Join because JOIN doesn't exist in GAE)
>
> You must change your model into siena syntax!
>
> Bakanis had rewritten the Yabe with Siena here:https://github.com/bakanis/bakanis-yabe-siena/tree/master/app
>
> Pascal
>

Pascal Voitot Dev

unread,
Oct 20, 2011, 3:38:00 AM10/20/11
to play-fr...@googlegroups.com
In Siena, you can do that only by embedding entities in each others using GAE native embedding.

...
@Embedded(mode=NATIVE)
Author author;
...

and you would certainly write it:
List<Comment> bobComments = Comment.all().filter("author.email", "b...@gmail.com").fetch();

but the author is stored in the entity directly and not in relational way as you imagine in RDBMS!

But remember GAE is a NoSQL DB with NO JOIN... so I'm not really sure your request would work with JPA in GAE in any way. Or, if it works, it means a few hidden queries to fetch the author with this email and then the post with this author. In Siena, we let you do the work as you want!
if Comment has an Author in the relational way, you would need to write:

Author author = Author.all().filter("email", "b...@gmail.com").get();
List<Comment> comments = Comment.all().filter("author", author).fetch();

regards
Pascal

Almas NURKHOZHAYEV

unread,
Oct 20, 2011, 4:10:20 AM10/20/11
to play-framework
Annotation
@Embedded(mode=Mode.NATIVE)
is not working as I expected, now I faced with such error:

User bob = new User("b...@gmail.com", "1111", "Bob");
bob.save();

// Create a new post
new Post(bob, "My first post", "Hello Post").save();

// Retrieve all posts created by Bob
List<Post> bobPosts = Model.all(Post.class).filter("author",
bob).fetch();

// Tests
assertEquals(1, Model.all(Post.class).count());
assertEquals(1, bobPosts.size());

Here, all Post count is 1 it is passed, but, bobPosts size is not 1,
it says that it is 0.

without @Embedded annotation I should use as you mentioned, But
Author author = Author.all().filter("email", "b...@gmail.com").get();
List<Comment> comments = Comment.all().filter("author",
author).fetch();

If I will use query little more complicated, like in this example:
List<Comment> bobComments =
Model.all(Comment.class).filter("post.author.email",
"b...@gmail.com").fetch();
assertEquals(3, bobComments.size());
There are list of authors which should be in query to retrieve me all
related posts,
to make this query, I have to make a loop and create bobComments list
manually?

Thanks

On Oct 20, 10:38 am, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> In Siena, you can do that only by embedding entities in each others using
> GAE native embedding.
>
> ...
> @Embedded(mode=NATIVE)
> Author author;
> ...
>
> and you would certainly write it:
> List<Comment> bobComments = Comment.all().filter("author.email", "
> b...@gmail.com").fetch();
>
> but the author is stored in the entity directly and not in relational way as
> you imagine in RDBMS!
>
> But remember GAE is a NoSQL DB with NO JOIN... so I'm not really sure your
> request would work with JPA in GAE in any way. Or, if it works, it means a
> few hidden queries to fetch the author with this email and then the post
> with this author. In Siena, we let you do the work as you want!
> if Comment has an Author in the relational way, you would need to write:
>
> Author author = Author.all().filter("email", "b...@gmail.com").get();
> List<Comment> comments = Comment.all().filter("author", author).fetch();
>
> regards
> Pascal
>

Pascal Voitot Dev

unread,
Oct 20, 2011, 4:24:58 AM10/20/11
to play-fr...@googlegroups.com
On Thu, Oct 20, 2011 at 10:10 AM, Almas NURKHOZHAYEV <alma...@gmail.com> wrote:
Annotation
@Embedded(mode=Mode.NATIVE)
is not working as I expected, now I faced with such error:

       User bob = new User("b...@gmail.com", "1111", "Bob");
       bob.save();

       // Create a new post
       new Post(bob, "My first post", "Hello Post").save();

       // Retrieve all posts created by Bob
       List<Post> bobPosts = Model.all(Post.class).filter("author",
bob).fetch();

       // Tests
       assertEquals(1, Model.all(Post.class).count());
       assertEquals(1, bobPosts.size());

Here, all Post count is 1 it is passed, but, bobPosts size is not 1,
it says that it is 0.

I'm not sure to understand exactly but in embedding BOB is embedded into the POST so it's a simple copy of BOB and not BOB himself!
If you try with:
List<Post> bobPosts = Model.all(Post.class).filter("author.email", "b...@gmail.com").fetch();
 
is it better?


without @Embedded annotation I should use as you mentioned, But
Author author = Author.all().filter("email", "b...@gmail.com").get();
List<Comment> comments = Comment.all().filter("author",
author).fetch();

If I will use query little more complicated, like in this example:
       List<Comment> bobComments =
Model.all(Comment.class).filter("post.author.email",
"b...@gmail.com").fetch();
       assertEquals(3, bobComments.size());
There are list of authors which should be in query to retrieve me all
related posts,
to make this query, I have to make a loop and create bobComments list
manually?


you have to fetch:
1) the author with the right email.
2) the comments associated to this author

You make 2 queries!
but as you don't have join, you can't do better if you design your model in a relational way :)

 

Almas NURKHOZHAYEV

unread,
Oct 20, 2011, 6:40:23 AM10/20/11
to play-framework
Hi Pascal,
in this situation, there will be several copies of same user.
is there any annotation to embed only reference of original object? :)
if no,
which one you advice to use?
actually I don't want to make several copies of the same data, so I
think to make little more queries than massing database.
am I right?

thanks


On Oct 20, 11:24 am, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> ...
>
> read more »

Pascal Voitot Dev

unread,
Oct 20, 2011, 6:49:35 AM10/20/11
to play-fr...@googlegroups.com
Your problem is just a question of design :)
NoSQL requires some behavior change with respect to SQL
Duplicating data is not a so bad manner in NoSQL.

You can have X comments associated to one Author using relational way. But you must do the join manually as explained in my sample.

You could also just store the interesting part of the author embedded into your comment such as the name.
From the name, you can retrieve the author when needed but in general, the name will be enough to display in a website!

Normalized models are nice on paper but rarely efficient in real-life apps!

Pascal



--
You received this message because you are subscribed to the Google Groups "play-framework" group.

Almas NURKHOZHAYEV

unread,
Oct 20, 2011, 7:04:41 AM10/20/11
to play-framework
Yeah, you'r right
I'm just designing the database, to make it more efficient.
I have a question:
what is happening when I create a column with datatype of another
table (entity)?
Is it also becoming a copy of original object? or reference? or
something else?

Thanks in advance

On Oct 20, 1:49 pm, Pascal Voitot Dev <pascal.voitot....@gmail.com>
wrote:
> Your problem is just a question of design :)
> NoSQL requires some behavior change with respect to SQL
> Duplicating data is not a so bad manner in NoSQL.
>
> You can have X comments associated to one Author using relational way. But
> you must do the join manually as explained in my sample.
>
> You could also just store the interesting part of the author embedded into
> your comment such as the name.
> From the name, you can retrieve the author when needed but in general, the
> name will be enough to display in a website!
>
> Normalized models are nice on paper but rarely efficient in real-life apps!
>
> Pascal
>
> ...
>
> read more »

Pascal Voitot Dev

unread,
Oct 20, 2011, 7:36:13 AM10/20/11
to play-fr...@googlegroups.com
On Thu, Oct 20, 2011 at 1:04 PM, Almas NURKHOZHAYEV <alma...@gmail.com> wrote:
Yeah, you'r right
I'm just designing the database, to make it more efficient.
I have a question:
what is happening when I create a column with datatype of another
table (entity)?
Is it also becoming a copy of original object? or reference? or
something else?


by default, if you put a reference to another class in your entity, it's by default @Referenced: it will store only the primary key of the referenced entity.
it's a classical X2One relation so it's a reference. The referenced entity doesn't need to know which entity references it.

@Embedded(NATIVE) copies the object into the local entity.
@Aggregated aggregates the linked entity into the entity group having as root node the current entity (look in GAE doc for more info).
@Owned creates a classic RDBMS X2One owned relation where current entity is the owner of the referenced entity and the referenced entity requires a link to its owner.

Look in SIena manuals, there are a few info about relations. The doc is not complete because it's really long to explain but it gives a few clues ;)

Pascal



 
> ...
>
> read more »

Reply all
Reply to author
Forward
0 new messages