7
这是我的POJO标注为实体如何使用hibernate创建新表时维护列顺序?
上述实体使用注释创建的,当我看向mysql数据库,这些列未在创建
@Entity
@Table(name = "book", catalog = "book_db")
public class Book {
private Integer bookId;
private String bookName;
private String bookShortDesc;
private String bookDesc;
private String bookAuthor;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "book_id", unique = true, nullable = false)
public Integer getBookId() {
return this.bookId;
}
@Column(name = "book_name", nullable = false, length = 256)
public String getBookName() {
return this.bookName;
}
@Column(name = "book_short_desc", nullable = false, length = 1024)
public String getBookShortDesc() {
return this.bookShortDesc;
}
等......顺序,我写下面,而是,第一列是book_id,然后是book_desc,然后是book_athor,然后是book_short_desc,然后是book_name。
我的问题是我如何告诉hibernate创建列的顺序与我在java代码中写的相同?
是否有任何注释?
问候
你的代码不应该依赖于数据库中列的排序。实际上,从技术上讲,不能保证在SELECT *时列将以特定顺序返回。如果您需要特定顺序的列,请在您的SQL查询中指定它。 – artbristol 2017-09-30 10:22:31