This is my pojo annotated as entity
@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;
}
etc......
the above entity is created using annotation, when i look to the mysql database,the columns are not created in the order, i have written below, instead , first columns is the book_id, then book_desc, then book_athor, then book_short_desc then book_name.
my question is how can i tell hibernate to create the columns the same order as i have written in the java code ??
is there any annotation for that ??
regards
Assuming you mean the database tables are generated via hbm2ddl.auto
being set to CREATE
or similar, there is no way to specify the order of the columns at least in 2008, according to one member of the Hibernate team.
My advice would be to create the database via separately maintained database scripts (possibly in conjunction with a script deployment/migration tool such as Flyway and perhaps also with hbm2ddl.auto = VALIDATE
to check the resulting schema matches the entities). Maintaining the database via scripts becomes much more necessary once the application goes into production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With