Search code examples
javapostgresqlspring-boothibernatejpa

org.postgresql.util.PSQLException: ERROR: column p1_0.pet_id does not exist


I have a Table named Pet. The following is the SQL script for it:

CREATE TABLE Pet (
    petId varchar(64) NOT NULL,
    name varchar(256) NOT NULL,
    petType varchar(64) NOT NULL,
    breedId varchar(64) NOT NULL,
    age integer,
    createdOn TIMESTAMP NOT NULL,
    createdBy varchar(64) NOT NULL,
    lastUpdatedBy varchar(64),
    lastUpdatedOn TIMESTAMP,
    PRIMARY KEY (petId),
    FOREIGN KEY (breedId) REFERENCES Breed(breedId)
);

I am getting the error org.postgresql.util.PSQLException: ERROR: column p1_0.pet_id does not exist when I use an insert query through JPA.

Following is the model that I have for Pet:

@Entity
@Table(name = "pet", schema = "petsetgo")
public class Pet extends BaseModel implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Id
    private String petId;
    private String name;
    @Enumerated(value = EnumType.STRING)
    private PetType petType;
    private Integer age;
    @JoinColumn(name = "breedid")
    private String  breedId;

Went through the previous questions and tried the following:

  • added schema name in the table annotaion
  • tried making all the values lowercase

Let me know if any other details are needed.


Solution

  • To solve this problem, you need to specify the column name explicitly. You need to specify "petid" as the @Column annotation in your Java entity class.

    @Id
    @Column(name = "petid")
    private String petId;