简体   繁体   中英

Why h2 not found a column

I have following problem

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Kolumna "CREATED_AT" nie istnieje Column "CREATED_AT" not found; SQL statement: insert into taco (id, created_at, name) values (null, ?, ?) [42122-200]

but in h2 console the column is present

在此处输入图像描述

i have following schema.sql code

create table if not exists Taco(
id identity,
name varchar(50) not null,
createdAt timestamp not null
);

and domain

package my.taco.models;

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

@Data
@Entity
public class Taco {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @NotNull
    @Size(min=5,message = "Nazwa musi składać się z przynajmniej pięciu znaków")
    private String name;

    private Date createdAt;

    @ManyToMany(targetEntity = Ingredient.class)
    @Size(min=1,message = "Musisz wybrac przynajmniej jeden składnik")
    private List<Ingredient> ingredients;

    @PrePersist
    void createdAt(){
        this.createdAt=new Date();
    }
}

so what`s wrong?

The default column name guessed by Hibernate (based on the attribute name) is CREATED_AT but yours is CREATEDAT

You can either rename the column in your database (recommended because it is more standard) or you can specify the column name to Hibernate like this:

@Column(name="CREATEDAT")
private Date createdAt;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM