I keep getting this error on start up of my Spring Boot Application
Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "ID"; SQL statement:
insert into bookings(bookings_name) values('Kris') [23502-199]
data.sql has
insert into bookings(bookings_name) values('Kris');
insert into bookings(bookings_name) values('Martin');
And I believe I have the annotations so that @Id is generated automatically
@Entity
class Bookings {
@Id
@GeneratedValue
@Column(name = "id", updatable = false, nullable = false)
private Long id;
private String BookingsName;
public Long getId() {
return id;
}
public String getBookingsName() {
return BookingsName;
}
public Bookings(String BookingsName) {
super();
this.BookingsName = BookingsName;
}
@Override
public String toString() {
return "Bookings [id=" + id + ", BookingsName=" + BookingsName + "]";
}
}
I am just starting to learn Spring boot and every example I find online doesn't seem to transalte to my very trivial example here.
Full Application.java
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Component
class BookingsCommandLineRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
}
}
interface BookingsRepository extends JpaRepository<Bookings, Long> {
Collection<Bookings> findByBookingsName(String BookingsName);
}
@RestController
class BookingsRestController {
@Autowired
BookingsRepository BookingsRepository;
@RequestMapping("/Bookingss")
Collection<Bookings> Bookingss() {
return this.BookingsRepository.findAll();
}
}
@Entity
class Bookings {
@Id
@GeneratedValue
@Column(name = "id", updatable = false, nullable = false)
private Long id;
private String BookingsName;
public Long getId() {
return id;
}
public String getBookingsName() {
return BookingsName;
}
public Bookings(String BookingsName) {
super();
this.BookingsName = BookingsName;
}
@Override
public String toString() {
return "Bookings [id=" + id + ", BookingsName=" + BookingsName + "]";
}
}