Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. @Entity
  2. @Table(name = "student")
  3. public class Student {
  4. @Id
  5. @GeneratedValue(strategy = GenerationType.IDENTITY)
  6. @Column(name = "id")
  7. private int id;
  8.  
  9. @Column(name = "first_name")
  10. private String firstName;
  11.  
  12. @Column(name = "last_name")
  13. private String lastName;
  14.  
  15. @OneToMany(targetEntity = Book.class, mappedBy = "student", cascade = CascadeType.ALL)
  16. private Set<Book> books = new HashSet<>();
  17.  
  18. public Student() {
  19.  
  20. }
  21. // accessors ...
  22. }
  23.  
  24. @Entity
  25. @Table(name = "book")
  26. public class Book {
  27.  
  28. @Id
  29. @GeneratedValue(strategy = GenerationType.IDENTITY)
  30. @Column(name = "id")
  31. private Integer id;
  32.  
  33. private String name;
  34.  
  35. @ManyToOne
  36. @JoinColumn(name = "student_id")
  37. private Student student;
  38.  
  39. public Book() {
  40. }
  41. //// accessors
  42. }
  43.  
  44. <!DOCTYPE hibernate-configuration PUBLIC
  45. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  46. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  47.  
  48. <session-factory>
  49.  
  50. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  51. <property name="connection.url">jdbc:mysql://localhost:3306/***?useSSL=false</property>
  52. <property name="connection.username">***</property>
  53. <property name="connection.password">***</property>
  54.  
  55.  
  56. <property name="connection.pool_size">2</property>
  57.  
  58.  
  59. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  60.  
  61.  
  62. <property name="show_sql">true</property>
  63. <property name="hibernate.hbm2ddl.auto">update</property>
  64.  
  65. <property name="current_session_context_class">thread</property>
  66.  
  67. </session-factory>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement