Announcement Announcement Module
Collapse
No announcement yet.
Relationship between Entities Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Relationship between Entities

    Hej,

    here I have a little example for a blog, that consists of posts with comments. A post could have many comments. A comment belongs to one post. I realized it as followed:

    Code:
    project --topLevelPackage example.blog --java 6
    persistence setup --database HYPERSONIC_IN_MEMORY --provider HIBERNATE 
    entity --class ~.domain.Post --testAutomatically 
    field string --fieldName title --notNull
    field string --fieldName article --notNull --sizeMin 1 --sizeMax 1000
    entity --class ~.domain.Comment --testAutomatically 
    field string --fieldName comment --notNull --sizeMin 1 --sizeMax 200
    field reference --fieldName post --type ~.domain.Post --notNull 
    field set --fieldName comments --type ~.domain.Comment --class ~.domain.Post --cardinality ONE_TO_MANY 
    controller all --package ~.web
    I tried then to create my own views. When I use model.addAttribute("posts", Post.findAllPosts()); to get all Posts, $post.comments is empty even if comments exist. Why is it empty? In contrast model.addAttribute("comments", Comment.findAllComments()); $comments.post returns the complete post object.

    Should the relation between post and comment constrcuted different? How to build a finder which does findAllPostsAndComments?

    Yours,
    Matthias.
Working...
X