Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name = "student")
- public class Student {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "id")
- private int id;
- @Column(name = "first_name")
- private String firstName;
- @Column(name = "last_name")
- private String lastName;
- @OneToMany(targetEntity = Book.class, mappedBy = "student", cascade = CascadeType.ALL)
- private Set<Book> books = new HashSet<>();
- public Student() {
- }
- // accessors ...
- }
- @Entity
- @Table(name = "book")
- public class Book {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "id")
- private Integer id;
- private String name;
- @ManyToOne
- @JoinColumn(name = "student_id")
- private Student student;
- public Book() {
- }
- //// accessors
- }
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <session-factory>
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://localhost:3306/***?useSSL=false</property>
- <property name="connection.username">***</property>
- <property name="connection.password">***</property>
- <property name="connection.pool_size">2</property>
- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="show_sql">true</property>
- <property name="hibernate.hbm2ddl.auto">update</property>
- <property name="current_session_context_class">thread</property>
- </session-factory>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement