Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ua.samuliak.messenger.entity;
- import org.hibernate.annotations.GenericGenerator;
- import javax.persistence.*;
- import java.util.HashSet;
- import java.util.Set;
- @Entity
- @Table(name = ""user"")
- public class User {
- @Id
- @GeneratedValue(generator = "increment")
- @GenericGenerator(name = "increment", strategy = "increment")
- private Long id;
- @Column(name = "id_room")
- private Long room;
- @Column(nullable = false, length = 20)
- private String login;
- @Column(nullable = false, length = 20)
- private String password;
- @Column(length = 2)
- private String country;
- @Column(length = 2)
- private Integer age;
- @Column(length = 25)
- private String occupation;
- @OneToMany(mappedBy = "user")
- private Set<Room> rooms = new HashSet<Room>();
- @OneToMany(mappedBy = "user_mes")
- private Set<Message> messages = new HashSet<Message>();
- public User() {}
- public User(String login, String password, String country) {
- this.login = login;
- this.password = password;
- this.country = country;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public Long getRoom() {
- return room;
- }
- public void setRoom(Long room) {
- this.room = room;
- }
- public String getLogin() {
- return login;
- }
- public void setLogin(String login) {
- this.login = login;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- public Integer getAge() {
- return age;
- }
- public void setAge(Integer age) {
- this.age = age;
- }
- public String getOccupation() {
- return occupation;
- }
- public void setOccupation(String occupation) {
- this.occupation = occupation;
- }
- // public Set<Room> getRooms() {
- // return rooms;
- // }
- //
- // public void setRooms(Set<Room> rooms) {
- // this.rooms = rooms;
- // }
- }
- package ua.samuliak.messenger.entity;
- import org.hibernate.annotations.GenericGenerator;
- import javax.persistence.*;
- import java.util.HashSet;
- import java.util.Set;
- @Entity
- @Table(name = "room")
- public class Room {
- @Id
- @GeneratedValue(generator = "increment")
- @GenericGenerator(name = "increment", strategy = "increment")
- private Long id;
- @Column(nullable = false, length = 30)
- private String title;
- @ManyToOne
- @JoinColumn(name = "user_id")
- private User user;
- @OneToMany(mappedBy = "room")
- private Set<Message> messages = new HashSet<Message>();
- public Room() {}
- public Room(String title, User user) {
- this.user = user;
- this.title = title;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- }
- package ua.samuliak.messenger.entity;
- import org.hibernate.annotations.GenericGenerator;
- import javax.persistence.*;
- @Entity
- @Table(name = "message")
- public class Message {
- @Id
- @GeneratedValue(generator = "increment")
- @GenericGenerator(name = "increment", strategy = "increment")
- private Long id;
- @ManyToOne
- @JoinColumn(name = "room_id")
- private Room room;
- @ManyToOne
- @JoinColumn(name = "user_id")
- private Room user_mes;
- @Column(nullable = false)
- private String value;
- public Message() {}
- public Message(Room room, String value) {
- this.room = room;
- this.value = value;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public Room getRoom() {
- return room;
- }
- public void setRoom(Room room) {
- this.room = room;
- }
- public Room getUser_mes() {
- return user_mes;
- }
- public void setUser_mes(Room user_mes) {
- this.user_mes = user_mes;
- }
- public String getValue() {
- return value;
- }
- public void setValue(String value) {
- this.value = value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement