Hibernate don't create Table in the DataBase

Viewed 40

Why Spring JPA does not create a Table in DB (MySQL) form Entity class ? IDEA - Eclipse EE

After run app!!

@Entity
@Table (name = "routess")
public class Routes {
    
    @Id
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Column (name = "id", updatable = false)
    private int id;
    
    @Column (name = "name", updatable = false)
    private String name;
    
    @Column (name = "startingpoint", updatable = false)
    private String startingpoint;
    
    @Column (name = "lastpoint", updatable = false)
    private String lastpoint;
    
    @Column (name = "date", updatable = false)
    private double date;
    
    @Column (name = "distance", updatable = false)
    private double distance;
    
    @Column (name = "numberofmembers", updatable = false)
    private int numberofmembers;
    
    public Routes () {}

Properties, dependency all good!

2 Answers

After going through the screenshots on drive, I noticed that your spring boot application main class is in completely different package than the entity classes and therefore spring is unable to scan the entities (by default spring scans same package or subpackages).

There are 2 possible solution to this problem.

1.Make your spring boot main class in outer package and put all other classes in inner packages so that spring will take care of scanning.

2.Make spring aware of the package in which your entity classes and repositories are present by using @EntityScan("com.demopackage")

Just add this line in your application.properties file, it will start creating the ddls:

spring.jpa.hibernate.ddl-auto=create
Related