我正在尝试使用Eclipse Kepler中的“JPA工具 - >生成来自实体的表...”从现有注释实体生成ddl。当我运行任务时,我得到一个带有sql脚本的文件来运行。问题是表创建语句中列的顺序不符合类定义中属性的顺序。
示例:
@Entity
@Table(name = "news", catalog = "myDatabase")
public class News implements java.io.Serializable {
private long id;
private String newsTitle;
private String newsTitle2;
private String newsText;
private Date created;
@Id
@GeneratedValue
@Column(name = "news_id", unique = true, nullable = false)
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "news_title")
public String getNewsTitle() {
return this.newsTitle;
}
public void setNewsTitle(String newsTitle) {
this.newsTitle = newsTitle;
}
@Column(name = "news_title2")
public String getNewsTitle2() {
return this.newsTitle2;
}
public void setNewsTitle2(String newsTitle2) {
this.newsTitle2 = newsTitle2;
}
@Lob
@Column(name = "news_text")
public String getNewsText() {
return this.newsText;
}
public void setNewsText(String newsText) {
this.newsText = newsText;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created")
public Date getCreated() {
return this.created;
}
public void setCreated(Date created) {
this.created = created;
}
}
脚本:
CREATE TABLE myDatabase.news (
news_id BIGINT NOT NULL UNIQUE, created DATETIME, news_text LONGTEXT,
news_title VARCHAR(255), news_title2 VARCHAR(255), PRIMARY KEY (news_id))
如何使用与java类对齐的列的顺序获取脚本?
非常感谢
斯特凡诺
答案 0 :(得分:0)
由于JPA中的抽象方法,这是不可能的。从理论上讲,你不知道下面的数据库类型,也不知道订单在那里是否重要。