0

I'm Using Spring boot(in IntelliJ IDE) in my backend application and what I'm trying to do is autogenerate PostgreSQL database with the provided details in my backend.

My model class Employee.java is as follows,

@Entity
@Table(name = "Employee")
public class Employee implements Serializable{

    private static final long serialVersionUID = -3009157732242241606L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long emp_id;

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

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

    @Column(name = "emp_dob")
    private Date emp_dob;

    @ManyToMany(cascade = CascadeType.MERGE)
    @JoinTable(name = "emp_skills",
            joinColumns = @JoinColumn(name = "emp_id", referencedColumnName = "emp_id"),
            inverseJoinColumns = @JoinColumn(name = "s_id",referencedColumnName = "s_id"))
    private Set<Skills> skills;

    public Employee(){ }

    public Employee(String emp_fname,String emp_email,Date emp_dob){
        this.emp_fname = emp_fname;
        this.emp_email = emp_email;
        this.emp_dob = emp_dob;
    }

    public Employee(Long emp_id,String emp_fname,String emp_email,Date emp_dob,Set<Skills> skills){
        this.emp_id = emp_id;
        this.emp_fname = emp_fname;
        this.emp_email = emp_email;
        this.emp_dob = emp_dob;
        this.skills = skills;
    }

    public Employee(Long emp_id,String emp_fname,String emp_email,Date emp_dob){
        this.emp_id = emp_id;
        this.emp_fname = emp_fname;
        this.emp_email = emp_email;
        this.emp_dob = emp_dob;
    }



    @Override
    public String toString(){
        return String.format("Employee[emp_id=%d,emp_fname='%s',emp_email='%s',emp_dob='%t']",emp_id,emp_fname,emp_email,emp_dob);
    }

    public long getEmp_id() {
        return emp_id;
    }

    public void setEmp_id(long emp_id) {
        this.emp_id = emp_id;
    }

    public String getEmp_fname() {
        return emp_fname;
    }

    public void setEmp_fname(String emp_fname) {
        this.emp_fname = emp_fname;
    }

    public String getEmp_email() {
        return emp_email;
    }

    public void setEmp_email(String emp_email) {
        this.emp_email = emp_email;
    }

    public Date getEmp_dob() {
        return emp_dob;
    }

    public void setEmp_dob(Date emp_dob) {
        this.emp_dob = emp_dob;
    }

    public Set<Skills> getSkills(){
        return  skills;
    }

    public void setSkills(Set<Skills> skills){
        if (skills == null || skills.isEmpty() || skills.equals("")){
            this.skills = Collections.emptySet();
        }
        else {
            this.skills = skills;
        }
        //this.skills = skills !=null? skills: Collections.emptySet();
    }

    }

What I want is generate employee table in the following order of fields,

emp_id | emp_fname | emp_email | emp_dob

But when executing the cord, the generated employee table is as follows, enter image description here

What is wrong with my code and how can I slove this issue?

PS: my application.properties file follows,

spring.datasource.url=jdbc:postgresql://localhost/assignment1
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.generate-ddl=true
INDRAJITH EKANAYAKE
  • 3,894
  • 11
  • 41
  • 63
  • 1
    The order of columns in a table does not really matter. –  Jul 22 '19 at 05:42
  • Hibernate use alphabetical ordering to generate columns. Follow [this answer](https://stackoverflow.com/a/1298327/2100051) for more details. – Rakib Jul 22 '19 at 05:54

0 Answers0