skip to Main Content

I have been trying to retrieve all data from the table but getting

"Caused by: org.postgresql.util.PSQLException: ERROR: column tenantenti0_.module_name does not exist"

I have tried all the below still the issue persists:

  1. Adding in application.properties file –> spring.jpa.properties.hibernate.default_schema=${your-default-schema-name}
  2. No camel case issue either in table column name or at code side.
  3. Have mentioned the schema name as well under @Table(name = "tenant_info", schema = "public"), however for me it’s public so shouldn’t effect only in case of custom schema it needs to be mentioned.
  4. Have tried using @namedQuery in entity class and @query in repository class still the same issue.

Below is my Entity class:

@Entity
@Table(name = "tenant_info", schema = "public")
@NamedQuery(name = "TenantEntity.findAll", query = "SELECT t FROM TenantEntity t")
@ApplicationScope
public class TenantEntity implements Serializable {
    
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "id")
    private int id;

    @Column(name = "tenant_id")
    private String tenantId;

    @Column(name = "module_name")
    private String moduleName;
    
    @Column(name = "url")
    private String url;
    
    @Column(name = "username")
    private String userName;
    
    @Column(name = "password")
    private String password;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public String getModuleName() {
        return moduleName;
    }

    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

Below is my Repository class:@Repository

public interface TenantRepository extends JpaRepository<TenantEntity, String> {

    public List<TenantEntity> findAll();

    public TenantEntity findByTenantId(String tenantId);

    public List<TenantEntity> findByModuleName(String moduleName);
}

Have attached the table pic.

CREATE TABLE IF NOT EXISTS public.tenant_info ( 
    id integer NOT NULL, 
    tenant_id text COLLATE pg_catalog."default" NOT NULL, 
    module_name text COLLATE pg_catalog."default" NOT NULL, 
    url text COLLATE pg_catalog."default" NOT NULL, 
    username text COLLATE pg_catalog."default" NOT NULL, 
    password text COLLATE pg_catalog."default" NOT NULL, 
    CONSTRAINT tenant_info_pkey PRIMARY KEY (id) 
) TABLESPACE pg_default;

enter image description here

2

Answers


  1. This can be caused because your database schema is not in synced with your Entity class. My advice is to inspect your database schema to see if your table has all the columns you expected. Might be more helpful if you show us your database table 😉

    Login or Signup to reply.
  2. I think that there could be two problems you are facing and I cannot comment so I have to answer just to try to help(Sorry if not useful). I believe that it may not be the schema but I would need you to upload your sql for the table to see it. It seems that it may be column not the table but the problem may be with

    @Column(name = "module_name")
    private String moduleName;
    

    If you look at your sql if you have quotes in postgres you may have to escape them in your java code for it to work properly. Which would make it

    @Column(name = ""module_name"")
    private String moduleName;
    

    Once again sorry if it isn’t helpful But can’t comment yet so really hopeful that this will help. When I had schema naming issue it wouldn’t even say column doesn’t exist but the table as a whole would be missing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search