Permalink
Browse files

[#1100] Docs: Tutorial: main.html template, JPA mapping description

  • Loading branch information...
Peter Hilton
Peter Hilton committed Nov 21, 2011
1 parent 75fadef commit d4d2d93c2168ef1d98db95a9251f33b269ab09df
Showing with 17 additions and 13 deletions.
  1. +16 −12 documentation/manual/guide1.textile
  2. +1 −1 documentation/manual/guide2.textile
@@ -133,20 +133,24 @@ Open the @/yabe/app/views/main.html@ template:
bc. <!DOCTYPE html>
<html>
<head>
<title>#{get 'title' /}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" media="screen"
href="@{'/public/stylesheets/main.css'}" />
<link rel="shortcut icon" type="image/png"
href="@{'/public/images/favicon.png'}" />
</head>
<body>
#{doLayout /}
</body>
<head>
<title>#{get 'title' /}</title>
<meta charset="${_response_encoding}">
<link rel="stylesheet" media="screen"
href="@{'/public/stylesheets/main.css'}">
#{get 'moreStyles' /}
<link rel="shortcut icon" type="image/png"
href="@{'/public/images/favicon.png'}">
<script type="text/javascript" charset="${_response_encoding}"
src="@{'/public/javascripts/jquery-1.5.2.min.js'}"></script>
#{get 'moreScripts' /}
</head>
<body>
#{doLayout /}
</body>
</html>
Do you see the @#{doLayout /}@ tag? This is where the content of @Application/index.html@ will be inserted.
Do you see the @#{doLayout /}@ tag near the bottom? This is where the content of @Application/index.html@ will be inserted.
We can try to edit the controller file to see how Play automatically reloads it. Open the @yabe/app/controllers/Application.java@ file in a text editor, and add a mistake by removing the trailing semicolon after the @render()@ call:
@@ -296,7 +296,7 @@ public Post(User author, String title, String content) {
}
...
Note how we have used the @mappedBy@ attribute to tell JPA that the @Comment@ class’ post field maintains the relationship. When you define a bi-directional relation with JPA it is very important to tell it which side will maintain the relationship. In this case, since the @Comments@ belong to the @Post@, it’s better that the @Comment@ class maintains the relationship.
Note how we have used the @mappedBy@ attribute to tell JPA that the @Comment@ class’ post field is the owning side that maintains the relationship. When you define a bi-directional relation with JPA it is important to specify which side will maintain the relationship. In this case, since @Comment@ instances belong to a @Post@, we define the relationship on the @Comment.post@ inverse relation.
We have set the @cascade@ property to tell JPA that we want @Post@ deletion be cascaded to @comments@. This way, if you delete a post, all related comments will be deleted as well.

0 comments on commit d4d2d93

Please sign in to comment.