0

class Entity

@Entity
    @Table
    public class Camera {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        private String name;
        private String place;
        private String address;
public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getPlace() {
        return place;
    }

    public void setId(Long id) {
        this.id = id;
    }

   //Constructors, getters and setters are not shown here

    }

application.properties configuration file

spring.datasource.url= jdbc:mysql://localhost:3306/springbootdb
spring.datasource.username=root
spring.datasource.password=
server.port=9000

I have this error

enter image description here

    Exception in thread "Thread-3" org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: La table 'springbootdb.camera' n'existe pas

I have to create manually table in the database to work :( Any idea ? is it a problem in the configuration file ?Thanks for your help :)

SouJd
  • 1
  • 1
  • 3

1 Answers1

1

Add the following property in your application.properties file:

spring.jpa.hibernate.ddl-auto=update

This will initialize your data base. Have a look at other properties as well according to spring docs:

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

Tanmay Delhikar
  • 1,275
  • 11
  • 16
  • I had getters and settters :( – SouJd May 13 '17 at 13:02
  • updated answer. Please try. This should now initialize your data base. – Tanmay Delhikar May 13 '17 at 14:23
  • Thanks, I really appreciate your help :D , it works now :D – SouJd May 13 '17 at 14:39
  • Hi, after creating automatically a table, i've tried to add another column it gives this error.Any idea please ? – SouJd May 16 '17 at 16:29
  • org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory – SouJd May 16 '17 at 16:29
  • http://stackoverflow.com/questions/33864363/error-creating-bean-with-name-entitymanagerfactory-defined-in-servletcontext-r – Tanmay Delhikar May 16 '17 at 17:29
  • http://stackoverflow.com/questions/40058001/error-creating-bean-with-name-entitymanagerfactory-defined-in-class-path-resou – Tanmay Delhikar May 16 '17 at 17:30