简体   繁体   中英

JPA Tools/EclipseLink - Generate table from entities - column order

I'm trying to generate ddl from existing annotated entities using "JPA tools --> Generate Tables from Entities..." in Eclipse Kepler. When I run the task, I get a file with sql scripts to run. The problem is that the order of the columns in the table creation statement fails to comply with the order of the attributes in the class definition.

Example:

 @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;
   }
}

Script:

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))

How can I get the scripts with the order of the columns aligned with the java class?

Thank you very much

Stefano

This is not possible due to the abstraction approach in JPA. Theoretically you don't know the kind of database below nor whether the order is important there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM