spring - Trying CrudRepository - H2 - TableNotFound -


below, configs

pom.xml

`<dependency>     <groupid>org.springframework.boot</groupid>      <artifactid>spring-boot-starter-data-jpa</artifactid>  </dependency>  <dependency>     <groupid>com.h2database</groupid>     <artifactid>h2</artifactid>  </dependency>` 

controller

@restcontroller public class sendsmscontroller {      @autowired     private databaseservice databaseservice;     @autowired     private sendsmsservice sendsmsservice;      @requestmapping(value="/sendsms", method=requestmethod.post)     public responseentity<sms> sendsms(@requestbody sms sms,@requestparam(required=false) string expirationdate) {          if(sms.getbody().length() > 160){             return new responseentity<sms>(httpstatus.unprocessable_entity);         }          databaseservice.savesms(sms);          return sendsmsservice.sendrequest(sms);     } } 

databaseservice

@data @service public class databaseservice {      @autowired     private smsrepository smsrepository;      public void savesms(sms sms) {         //i try smsrepository.save(sms)         smsrepository.save(new sms(sms.getto(),sms.getto(),sms.getbody()));     } } 

smsrepository

public interface smsrepository extends crudrepository<sms, long> {  } 

sms class

@data @entity @jsonignoreproperties(ignoreunknown = true) public class sms {      @id     @generatedvalue(strategy=generationtype.auto)     private long id;     @jsonproperty     private string from;     @jsonproperty     private string to;     @jsonproperty     private string body;      public sms(string from, string to, string body){         this.from = from;         this.to = to;         this.body = body;     };      public sms(){     }  } 

config

@configuration public class config {      @bean     public sendsmsservice sendsmsservice(){         return new sendsmsservice();     }      @bean     public databaseservice databaseservice(){         return new databaseservice();     } 

this issue occurs when code reaches "smsrepository.save(sms)". follow tutorial https://spring.io/guides/gs/accessing-data-jpa/ think missing configs. thank help!

the error again: org.springframework.dao.invaliddataaccessresourceusageexception: not prepare statement; sql [insert sms (id, body, from, to) values (null, ?, ?, ?)]; nested exception org.hibernate.exception.sqlgrammarexception: not prepare statement

caused by: org.h2.jdbc.jdbcsqlexception: table "sms" not found; sql statement: insert sms (id, body, from, to) values (null, ?, ?, ?) [42102-187] 

the problem in class.

after work

public class sms {      @id     private string id;     @jsonproperty     @column(name="fromnumber")     private string from;     @jsonproperty     @column(name="tonumber")     private string to;     @jsonproperty     @column(name="bodymessage")     private string body; 

Comments