0

Once again I'm to ask your precios help to solve a problem with Hibernate, Springboot, Postgresql. In my project I have dozens of tables I read and write on, I've used same configuration for every tables without problems, but I'm having some problems with one of them:

This is the Class mapping my table:

package com.mycompany.ingestion.entities.mappingdb;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="td_titauto")
public class TdTitAuto {
    
    
    @Id
    @SequenceGenerator(name = "seq_td_titauto", sequenceName = "seq_td_titauto", allocationSize=1)
    @GeneratedValue(generator = "seq_td_titauto", strategy = GenerationType.SEQUENCE)
    private Long idTitAuto;
    private String idAuto;
    public Long getIdTitAuto() {
        return idTitAuto;
    }
    public void setIdTitAuto(Long idTitAuto) {
        this.idTitAuto = idTitAuto;
    }
    public String getIdAuto() {
        return idAuto;
    }
    public void setIdAuto(String idAuto) {
        this.idAuto = idAuto;
    }

}

When I run the project, I got following error: ERROR: column tdtitauto0_.id_tit_auto does not exist Hint: Perhaps you meant to reference the column "tdtitauto0_.id_titauto".

The name of the table on DB is td_titaut. If I add the name of the schema on the annotation @Table, nothing changes, but If I remove the @Table annotation, I got the following error:

ERROR: relation "td_tit_auto" does not exist In this case I have no idea why an underscore char is added (the table is named td_titauto with just one underscore).

I've tried also to use a config file instead and as well as annotation, but nothing change. Any suggestions? Thank you so much, I really appreciate My best regards Steph

1 Answer 1

2

It seems you have a table in your db called td_titauto but the default name for an entity is td_tit_auto. It's probably because the entity name is TdTitAuto instead of TdTitauto.

Hibernate ORM is expecting a column on the table called id_tit_auto but I suspect the column name in your db is instead id_titauto. So, you need to change the mapping this way:

@Entity
@Table(name="td_titauto")
public class TdTitAuto {
    @Id
    @Column(name="id_titauto")
    @SequenceGenerator(...)
    @GeneratedValue(...)
    private Long idTitAuto;
}

Assuming that the name of the column with the id is id_titauto.

Probably, this would work as well:

@Entity
public class TdTitauto {
    @Id
    @SequenceGenerator(...)
    @GeneratedValue(...)
    private Long idTitauto;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Oh yes, now it works fine. Thank you so much, It was a couple of days I was fighting with this problem.
No problem, could you mark this as the right solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.