Hibernate不会创建实现Serializable接口的表吗?

时间:2019-02-28 17:41:17

标签: java spring hibernate spring-mvc spring-webflow

我有一个有关Spring Data,MVC和Web Flow的小型项目。另外,我在Spring Web Flow中使用了2个实体,因此它们必须实现Serializable接口,但是我注意到Hibernate不会创建表来实现它,为了证明这一点,我只是复制了我的实体,删除了创建的“ implements Serializable”新的类并将实体代码粘贴到此处,就创建了新表。怎么运行的 ?如何从实现Serializable的实体创建表,有可能吗?

实体代码:

@Table(name = "users")
@Entity
public class User implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "idUsers")
private int id;
@Column(name = "login")
@Size(min = 3, max = 15,message = "Неправильний розмір")
@NotEmpty(message = "Не може бути пустим!")
private String login;
@Size(min = 6, max = 21,message = "Неправильний розмір")
@NotEmpty(message = "Не може бути пустим!")
@Column(name = "password")
private String password;
@NotNull(message = "Не може бути пустим!")
@Column(name = "email")
private String email;
@Column(name = "photo")
private String path;
@Column(name = "about")
private String about;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}



@OneToMany(
        fetch = FetchType.EAGER,
        mappedBy = "user",
        cascade = CascadeType.ALL,
        orphanRemoval = true
)
private Set<CommentsToBook> commentsToBooks;

public Set<CommentsToBook> getCommentsToBooks() {
    return commentsToBooks;
}

public void setCommentsToBooks(Set<CommentsToBook> commentsToBooks) {
    this.commentsToBooks = commentsToBooks;
}

public Set<BookOrder> getOrders() {
    return orders;
}

public void setOrders(Set<BookOrder> orders) {
    this.orders = orders;
}

@OneToMany(
        fetch = FetchType.EAGER,
        mappedBy = "user",
        cascade = CascadeType.ALL,
        orphanRemoval = true
)
private Set<BookOrder> orders;


public String getPath() {
    return path;
}

public String getAbout() {
    return about;
}

public void setAbout(String about) {
    this.about = about;
}

public void setPath(String path) {
    this.path = path;
}

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 getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}
}

第二个:

@Entity
@Table(name = "booook_order")
public class BookOrder implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private int id;
@Column(name = "bank_card")
private String bankCardId;
@Column(name = "user_name")
private String custName;

public User getUser() {
    return user;
}
@ManyToMany(fetch =  FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "book", joinColumns = {
        @JoinColumn(name = "id")
},inverseJoinColumns = {@JoinColumn(name = "idlibrary")})
private Set<Book> booksList;


@Column(name ="novaposhta-vid")
private String NPVid;

public String getNPVid() {
    return NPVid;
}

public void setNPVid(String NPVid) {
    this.NPVid = NPVid;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

@Column(name = "city")
private String city;

public void setUser(User user) {
    this.user = user;
}

@ManyToOne(cascade = CascadeType.ALL,
        fetch = FetchType.EAGER)
@JoinColumn(name = "idUsers")
private User user;

public String getCustName() {
    return custName;
}

public void setCustName(String custName) {
    this.custName = custName;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public Set<Book> getBooksList() {
    return booksList;
}

public void setBooksList(Set<Book> booksList) {
    this.booksList = booksList;
}

public String getBankCardId() {
    return bankCardId;
}

public void setBankCardId(String bankCardId) {
    this.bankCardId = bankCardId;
}
}

0 个答案:

没有答案