Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 not creating table when using @Column(name="someName",columnDefinition = "FLOAT(10,7)")

I'm using SpringBoot 1.5.14.RELEASE and com.h2database:h2. I have an entity that looks like this

//.... annotations here
public class SomeEntity {

    @Id
    private Long id;
    @Column(name = "some_columne_name", columnDefinition = "FLOAT(10,7)")
    private Double someColumnName;
}

The H2 is started with spring.jpa.generate-ddl=true and spring.jpa.hibernate.ddl-auto=create

But for some reason, H2 does not create the table because later in the code, when a select query run it throws SQL Error:42102, Table not found

if I start H2 without the columnDefinition in the entity then it creates the table successfully

How to create tables in H2 with columnDefinition in entities ?

like image 490
user3344591 Avatar asked Sep 11 '25 14:09

user3344591


1 Answers

According to H2 Data Types documentation the correct format is FLOAT(precisionInt) and not FLOAT(precisionInt, precisionInt). So all you have to do is to change column definition part and it will work.

e.g. @Column(name = "some_columne_name", columnDefinition = "FLOAT(10)")

As for what should be the value of precisionInt:

  • Precision value for FLOAT type name should be from 0 to 24
  • Precision value for DOUBLE type name should be from 25 to 53
like image 55
balazs Avatar answered Sep 13 '25 07:09

balazs