First of all, I'd like to say I'm enjoying Play from what I've seen so
far.
I'm meeting something.. quite weird I'd say and I'd like to ask if
this is a bug. It happened when I was going through the yabe tutorial
and I verified it against the play 1.0.1.
It has something to do with the unit test, in the fullTest() method of
the BasicTest.java
<code>
// Find the most recent post
Post frontPost = Post.find("order by postedAt
desc").first();
assertNotNull(frontPost);
assertEquals("About the model layer", frontPost.title);
// Check that this post has two comments
155 //assertEquals(2, frontPost.comments.size());
// Post a new comment
frontPost.addComment("Jim", "Hello guys");
159 assertEquals(3, frontPost.comments.size());
assertEquals(4, Comment.count());
</code>
If I remove line 155 and run the unit test, I get:
Failure, expected:<3> but was:<4>
In /test/BasicTest.java, line 159 :
assertEquals(3, frontPost.comments.size());
If I add back line 155, or even wrap it in System.out, it's fine. It's
interesting in the quantum mechanical sense that If I don't read the
value, the error will always be there, but if I read it, then the test
would pass.
I'm still new to the framework so I'm wondering if there's something
I'm missing or it's a.. bug.
Thanks!
> --
> 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
> .
>
public Post addComment(String author, String content) {
43: Comment newComment = new Comment(this, author,
content).save();
44 this.comments.add(newComment);
}
lNo 43 --> we created comment and saved it.
lNo 44 --> we created an association --> we dont need to save it here?
if you add new line 45: this.save() --> everything should be fine.
Don't ask me why yet :) I am just trying to find out how play wraps
the code with transactions.
cheers
On Mar 18, 9:34 am, Guillaume Bort <guillaume.b...@gmail.com> wrote:
> Yes it's strange. I'll investiguate.
>
> It's interesting in the quantum mechanical sense that If I don't read the
> value, the error will always be there, but if I read it, then the test
> would pass.
In fact it is not as simple. When you call "frontPost.comments.size()"
hibernate will generate a "select count ..." query. But before
generating this query, it will take care of flushing all not yet saved
object states to the database.
So yes here reading a value on a persistent object can have side
effect when running in the same database transaction.
Yes you're right, it was the problem.
In fact it is not as simple. When you call "frontPost.comments.size()"
> It's interesting in the quantum mechanical sense that If I don't read the
> value, the error will always be there, but if I read it, then the test
> would pass.
hibernate will generate a "select count ..." query. But before
generating this query, it will take care of flushing all not yet saved
object states to the database.
So yes here reading a value on a persistent object can have side
effect when running in the same database transaction.
cheers
Good job!