Spring Boot and H2 Table Population Error: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL

NullWolf

I am having trouble getting an H2 In Memory database to populate. The idea here to have the BuildingCode which is unique as a primary key and id.

I get the following class level errors:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table property add column building_code varchar(255) not null" via JDBC Statement

Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "BUILDING_CODE"; SQL statement:

@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "Property")
public class Property {

    @Id
    @Column(name = "BuildingCode")
    String id;

    @Column(name = "Latitude")
    Float latitude;

    @Column(name = "Longitude")
    Float longitude;

    @Column(name = "BuildingName")
    String buildingName;

    @Column(name = "BuildAbr")
    String buildAbr;

    @Column(name = "Address")
    String address;

    @Column(name = "SquareFt")
    Long squareFt;

    @Column(name = "AssetId")
    Long assetId;

    public String getLatLong(){
        return "[" + this.getLatitude() + "," + this.getLongitude() + "]";
    }
}

Table Creation and Sample Insert

CREATE TABLE Property(
   Latitude       NUMERIC(9,6) NOT NULL
  ,Longitude      NUMERIC(10,6) NOT NULL
  ,BuildingCode   VARCHAR(5) NOT NULL PRIMARY KEY
  ,BuildingName   VARCHAR(42) NOT NULL
  ,BuildAbr       VARCHAR(18) NOT NULL
  ,Address        VARCHAR(42) NOT NULL
  ,SquareFt       INTEGER
  ,AssetId        INTEGER
);

INSERT INTO Property(Latitude,Longitude,BuildingCode,BuildingName,BuildAbr,Address,SquareFt,AssetId) VALUES (43.453696,-76.544895,'0006','Lanigan Hall','LANIGAN-6','some address',88200,1743);

Also here is my application.properties

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url = jdbc:h2:mem:testdb:DB_CLOSE_ON_EXIT=FALSE

spring.jpa.show-sql=false
spring.jpa.properties.hibernate.generate_statistics=false
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
Crack_it

In Entity class you have defined column name in camel case i.e. BuildingCode,

@Id
@Column(name = "BuildingCode")
private String id;

This will make JPA to expect a column named building_code in the DB table and if it does not find one, it will create column named building_code with data size varchar(255) and "NOT NULL".

In your insert query, it has value for BuildingCode column but no value for newly created building_code column, hence the error -

**NULL not allowed for column "BUILDING_CODE"**

Same is applicable for other Camel-cased columns as well, viz.

BuildingName, 
BuildAbr,
SquareFt,
AssetId 

Conclusion: If you do not want JPA to create columns with underscore, do not mention column names in entity in camel case. Your code will work if you change column definition as below:

@Id
@Column(name = "Buildingcode") //change camel case to title case
private String id;

But, instead I would suggest simply changing column names in create table and insert table scripts to have underscore as below:

    create table property(
      latitude        NUMERIC(9,6) NOT NULL,
      longitude       NUMERIC(10,6) NOT NULL,
      building_code   VARCHAR(5) NOT NULL PRIMARY KEY,
      building_name   VARCHAR(42) NOT NULL,
      build_abr       VARCHAR(18) NOT NULL,
      address         VARCHAR(42) NOT NULL,
      square_ft       INTEGER,
      asset_id        INTEGER
    );
        
    insert into property 
    ( latitude, 
         longitude,
         building_code,
         building_name,
         build_abr,
         address,
         square_ft,
         asset_id) 
    values (43.453696,
         -76.544895,
         '0006',
         'Lanigan Hall',
         'LANIGAN-6',
         'some address',
         88200,
         1743);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Hibernate Error executing DDL via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException:Error executing DDL via JDBC Statement

Spring execption:org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table post

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing column [customer_number] in table [customers]

Hibernate can't create a table: org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table PSQLException

Spring boot error org.hibernate.MappingException: Could not determine type

Spring Boot Error executing DDL via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement in SpringBoot with h2 and JPA

Executing H2 under Spring Boot

org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement

Why does Spring Boot with embedded H2 throw a 'org.h2.message.DbException' error?

Spring Boot, JPA error: "Error executing DDL via JDBC Statement"

Spring boot error org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL

Error executing DDL "create table in Spring Data JPA?

SQL Error during Spring boot start for creating table for H2

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table TABLE_JSON

Getting error : Unknown service requested [org.hibernate.boot.registry.classloading.spi.ClassLoaderService]

how to resolve error executing ddl commands in spring boot

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "CREATE FUNCTION"

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL create table index

I'm trying run a spring bot application and it shows a CommandAcceptanceException error executing DDL

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table movie

Spring boot exception error executing ddl

Error executing DDL "insert into ..." via JDBC Statement in Spring Boot

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table departement drop foreign key XX" via JDBC Statement

ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelpe / org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL

org.hibernate.tool.schema.spi.CommandAcceptanceException trying to connect a MYSQL database

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive