Guest User

Untitled

a guest
Dec 4th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public class Book {
  2. @Id
  3. @GeneratedValue
  4. private int bookId;
  5. private String name;
  6. @OneToMany(mappedBy = "Book")
  7. private List<Chapter> chapters;
  8. }
  9.  
  10. public class Chapter {
  11. @Id
  12. @GeneratedValue
  13. @ManyToOne
  14. private int chapterId;
  15. private String name;
  16. @JoinColumn(name = "bookId")
  17. private Book book;
  18. }
  19.  
  20. {
  21. "id" : "1"
  22. "name" : "Alice in wonderland"
  23. }
  24.  
  25. {
  26. "id": "1",
  27. "name" : "Down the Rabbit Hole"
  28. }
  29.  
  30. {
  31. "chapterId" : 1,
  32. "name" : "Down the Rabbit Hole",
  33. "bookId" : "1"
  34. }
  35.  
  36. chapter = (Chapter) session.get( Chapter.class, chapterId );
  37.  
  38. {
  39. "chapterId" : 1,
  40. "name": "Down the Rabbit Hole",
  41. "Book" : {
  42. "bookId" : "1",
  43. "name": "Alice in wonderland"
  44. }
  45. }
  46.  
  47. {
  48. "name" : "The Pool of Tears",
  49. "bookId" : "1"
  50. }
  51.  
  52. {
  53. "name" : "The Pool of Tears",
  54. "Book" : {
  55. "bookId" : "1",
  56. "name" : "Alice in wonderland"
  57. }
  58. }
Add Comment
Please, Sign In to add comment