天道酬勤,学无止境

org.postgresql.util.PSQLException: The column name usuario was not found in this ResultSet

I am getting the following error: org.postgresql.util.PSQLException: The column name usuario was not found in this ResultSet.

However, I have the following column usuario declared properly in the appropriate classes!

UsuariosGruposDAO.class

public Object objectFactory(ResultSet rs) {
        try {
            UsuariosGrupos usergroup = new UsuariosGrupos(rs.getString("usuario"), rs.getString("grupo"));
            return usergroup;
        } catch (SQLException e) {
            e.printStackTrace();
            // retorno do método
            return null;
        }
    }

UsuariosGrupos.class

public class UsuariosGrupos {

    private String usuario;
    private String grupo;

    public UsuariosGrupos() {
    }

    public UsuariosGrupos(String usuario, String grupo) {
        this.usuario = usuario;
        this.grupo = grupo;
    }

The error appears in the following line:

       ugList.add((UsuariosGrupos) objectFactory(rs));  

of my List method:

List<UsuariosGrupos> ugList = null;
    try {
        //Conecta no banco
        conn.conectar();
        //Prepara o preparedStatment
        stmt = (PreparedStatement) conn.getPreparedStatement("SELECT * from usuarios_grupos");
        //Executa a instrucao SQL
        ResultSet rs = stmt.executeQuery();
        ugList = new ArrayList<UsuariosGrupos>();
        //Enquanto ouver resultSet
        while (rs.next()) {
            ugList.add((UsuariosGrupos) objectFactory(rs));
        }
        System.out.println("################################UsuariosGrupos OK################################");
    } catch (SQLException e) {
        System.out.println("################################UsuariosGrupos Falhou################################");
        e.printStackTrace();
    } finally {
        conn.desconectar();
    }
    return ugList;
}

The weird thing is when I test my List separately, the datatable displays the appropriate results. However, when I run my entire application, nothing shows up, and I get that error stating the column usuario cannot be found in the resultset. Any suggestions?

The table has two fields:

Usuarios | Grupos

admin        2
admin        3

It displays fine, when I separate my jsf code, but doesn't display the data when I have it on one JSF file.

标签

评论

Your table dump shows the field as "Usarios" but you are doing a rs.getString("usuario"). Shouldln't that be the following?

rs.getString("usuarios")

If that doesn't work then I would recommend debugging your code, putting a breakpoint on the getString line and looking at the ResultSet to see what the field names are there.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Caused by: org.postgresql.util.PSQLException: ERROR: column xxx.xxx does not exist
    最近在做压力测试,需要将生产上的两个数据库数据导到测试环境上来,因为涉及到数据库的操作都是交给DBA来做的,所以就没有管,然后当DBA跟我说一切OK之后,为了保险起见我还是决定在本地试一下,项目是正常起来了,当我打一个get请求之后。。。,出现了尴尬的一幕,报错啦:relation "xxx" does not exist 说我的表不存在,纳尼?数据库连接、entity一切都没有变的呀,联想起以前也出现过类似的情况,是数据库的search_path没有修改,于是向亲爱的DBA同事反映了,效率很快的改好了,再试了下,发现这个数据库确实是好了,再试试另一个数据库,发现又报错了,但是这次的和之前的报错不一样了,上次是表找不到,这次是列找不到,报错信息如下: exception occurs: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet Caused by: org.postgresql.util.PSQLException: ERROR: column shiplocati0_
  • PSQLException: 在这个 ResultSet 中找不到列名 clazz_(PSQLException: The column name clazz_ was not found in this ResultSet)
    问题 我正在尝试获取PlaceEntity 。 我以前存储了一堆GooglePlaceEntity对象,其中 @Entity @Table(name = "place") @Inheritance( strategy = InheritanceType.JOINED ) public class PlaceEntity extends AbstractTimestampEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; } 和 @Entity @Table(name = "google_place") public class GooglePlaceEntity extends PlaceEntity { // Additional fields .. } 但是,我既不想发送存储在google_place信息,也不想不必要地加载它。 出于这个原因,我只取 public interface PlaceRepository extends JpaRepository<PlaceEntity, Long> { @Query(value = "" + "SELECT * " + "FROM place " + "WHERE earth_distance( " + " ll_to
  • org.postgresql.util.PSQLException:错误:列 user0_.id 不存在 - 休眠(org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist - Hibernate)
    问题 我有一个使用 hibernate 映射到 postgres 数据库的模型类。 我的模型类是: @Entity @Table(name="USER") public class User { @Id @GeneratedValue @Column(name="id") private long id; @Column(name="username", unique=true) private String username; @Column(name="email") private String email; @Column(name="created") private Timestamp created; public User(long id, String username, String email) { this.id = id; this.username = username; this.email = email; } } 我尝试使用以下查询检索用户名为“adam”的用户: tx = session.beginTransaction(); TypedQuery<User> query = session.createQuery("FROM User u WHERE u.username = :username", User.class)
  • org.hibernate.HibernateException [org.postgresql.util.PSQLException: 不能在自动提交模式下使用大对象。](org.hibernate.HibernateException [org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode.])
    问题 我知道之前可能有人问过这个问题,但我的问题的不同之处在于我使用的是扩展的 PersistenceUnit ,而且我不是管理事务的人,因为服务器负责管理它。 顺便说一句,我正在将 JPA(2.1) 与 hibernate(4.3.10) 提供程序、PostgreSQL(9.5) 数据库和自由服务器一起使用 这是我在浏览器中得到的 这是我在简单视图中的实体 @Entity public class GeoArea{ private Integer id;//Auto Generated private String name; private Set<TourismOrganization> organizations; //getter and setter methods @ManyToMany(mappedBy = "geoAreas") public Set<TourismOrganization> getOrganizations() { return organizations; } public void setOrganizations(Set<TourismOrganization> organizations) { this.organizations = organizations; } } @Entity public class
  • 异常:org.postgresql.util.PSQLException:错误:“调用”处或附近的语法错误(Exception : org.postgresql.util.PSQLException: ERROR: syntax error at or near "call")
    问题 我正在开发一个应用程序,其中 hibernate 和 postgresql 并给出以下错误 org.postgresql.util.PSQLException:错误:“调用”处或附近的语法错误 有人可以告诉我我哪里出错了。 我正在使用 Postgres 9.4。 HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value type Exception report message Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.web.util.NestedServletException
  • org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist - Hibernate
    I have a model class that is mapped to a postgres database using hibernate. My model class is: @Entity @Table(name="USER") public class User { @Id @GeneratedValue @Column(name="id") private long id; @Column(name="username", unique=true) private String username; @Column(name="email") private String email; @Column(name="created") private Timestamp created; public User(long id, String username, String email) { this.id = id; this.username = username; this.email = email; } } I try to retrieve the user with username "adam" using the below query: tx = session.beginTransaction(); TypedQuery<User>
  • org.postgresql.util.PSQLException: 错误: 关系 “xxxx“ 不存在
    使用的是postgresql数据库,以往使用数据库是在XML文件中自己编写sql语句。会在表名上加入“”,这次使用了以往没有使用过的。网上找了好多。说是表名不能有大写。可就算改成是小写了也还是不行,一直报这个不存在的错误 找到了一个关于 currentSchema 这个属性,但是自己也不知道这个怎么设置。学着网络上写的都不行,就慢慢的去试。总数给搞出来了。原来是表的模式名字 更改下连接字符串即可 useUnicode=true&characterEncoding=utf8&currentSchema=public&stringtype=unspecified 或者实体类加入 @TableName(autoResultMap = true, value = "machiningday",schema = "public") 来源:https://blog.csdn.net/u012985257/article/details/110220604
  • org.postgresql.util.PSQLException:列索引超出范围:3,列数:2(org.postgresql.util.PSQLException: The column index is out of range: 3, number of columns: 2)
    问题 我决定通过在其中添加使用spring security和数据库的身份验证来修改我的应用程序。 在使用普通身份验证和XML中的user和password 。 工作正常。 我的authentication-manager如下所示 <authentication-manager> <authentication-provider> <jdbc-user-service data-source-ref="dataSource" users-by-username-query="select username, password from pmc.username_password where username=?;" authorities-by-username-query="select a.username, b.role from pmc.username_password a, pmc.username_role b where a.username = b.username and a.username=?;" /> </authentication-provider> </authentication-manager> 但是,当我尝试进行身份验证时,我遇到了异常 org.springframework.security.authentication
  • JPA one-to-one insert how to do it properly with eclipselink
    I am trying to do simple one-to-one mapping with JPA and EclipseLink. I have the following DB structure in PostgreSQL CREATE TABLE public.employee ( id SERIAL, firstname VARCHAR(20), lastname VARCHAR(20), CONSTRAINT employee_pkey PRIMARY KEY(id) ); CREATE TABLE public.employee_info ( id INTEGER NOT NULL, info TEXT DEFAULT ''::text NOT NULL, CONSTRAINT employee_info_pkey PRIMARY KEY(id), CONSTRAINT employee_info_fk FOREIGN KEY (id) ); and I am trying to reflect this as the following code: Employee: @Entity @Table(name = "employee") public class Employee implements Serializable { private static
  • Exception : org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
    I am working on a application in which hibernate and postgresql and giving the following error org.postgresql.util.PSQLException: ERROR: syntax error at or near "call" Can someone tell me where I am going wrong. I am using Postgres 9.4. HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value type Exception report message Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value description The server encountered an internal error that
  • 内部异常:org.postgresql.util.PSQLException:错误:关系“producttype_productitem”不存在(Internal Exception: org.postgresql.util.PSQLException: ERROR: relation "producttype_productitem" does not exist)
    问题 在自学 JAX-RS 和 JPA 的过程中。 当我在 Glassfish server 3.1.2 上运行项目时,我偶然发现了以下异常。 然而,JPA 实现作为一个独立的应用程序运行良好。 内部异常:org.postgresql.util.PSQLException:错误:关系“producttype_productitem”不存在位置:65 错误代码:0 调用:SELECT t1.“productCode”、t1.COST、t1.ITEMCODE、t1.ITEMNAME FROM ProductType_ProductItem t0 , "ProductItem" t1 WHERE ((t0.ProductType_productCode = ?) AND (t1."productCode" = t0.item_productCode)) bind => [1个参数绑定] 我使用 Eclipse Kepler IDE、Glassfish Server 3.1.2、Jersey for JAX-RS、Eclipselink 2.3 for JPA Implementation 和 PostgresSQL for database。 CREATE TABLE "ProductType" ( "productCode" integer NOT NULL, "productName
  • PSQLException: ERROR: syntax error at or near
    I have what I thought was a straight forward relation in JPA. Looks like this. CompanyGroup: @Entity @Table public class CompanyGroup implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @Column(name = "name") private String name; @JoinColumn(name = "companies") @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List<Company> companies; } Company: @Entity @Table public class Company implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "name") private String name; @JoinColumn(name
  • PSQLException:当前事务中止,命令被忽略,直到事务块结束(PSQLException: current transaction is aborted, commands ignored until end of transaction block)
    问题 我在JBoss 7.1.1 Final的server.log文件中看到以下(截断的)堆栈跟踪: Caused by: org.postgresql.util.PSQLException: ERROR: current transaction is aborted, commands ignored until end of transaction block at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags
  • Caused by: org.postgresql.util.PSQLException: 错误: FROM 中的子查询必须有一个别名
    记一个报错(粗心大意所致):背景是项目数据库从Oracle切换成PostgreSQL,使用Spring Data Jpa提供的SimpleJpaRepository做查询。下面是引起报错的查询示例: findTopByParam1AndParam2(param1, param2); 报错信息: [WARN] [http-nio-8483-exec-3] [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] 129 - SQL Error: 0, SQLState: 42601 [ERROR] [http-nio-8483-exec-3] [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] 131 - 错误: FROM 中的子查询必须有一个别名 Caused by: org.postgresql.util.PSQLException: 错误: FROM 中的子查询必须有一个别名 Hint: 例如, FROM (SELECT ...) [AS] foo. Position: 15 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440) at org
  • JPA一对一插入如何正确使用eclipselink(JPA one-to-one insert how to do it properly with eclipselink)
    问题 我正在尝试使用 JPA 和 EclipseLink 进行简单的一对一映射。 我在 PostgreSQL 中有以下数据库结构 CREATE TABLE public.employee ( id SERIAL, firstname VARCHAR(20), lastname VARCHAR(20), CONSTRAINT employee_pkey PRIMARY KEY(id) ); CREATE TABLE public.employee_info ( id INTEGER NOT NULL, info TEXT DEFAULT ''::text NOT NULL, CONSTRAINT employee_info_pkey PRIMARY KEY(id), CONSTRAINT employee_info_fk FOREIGN KEY (id) ); 我试图将其反映为以下代码: 员工: @Entity @Table(name = "employee") public class Employee implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column
  • PSQLException: 错误: 语法错误在或附近(PSQLException: ERROR: syntax error at or near)
    问题 我认为在 JPA 中有一种直接的关系。 看起来像这样。 公司集团: @Entity @Table public class CompanyGroup implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private Long id; @Column(name = "name") private String name; @JoinColumn(name = "companies") @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List<Company> companies; } 公司: @Entity @Table public class Company implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "name") private String name; @JoinColumn(name = "users") @OneToMany(fetch = FetchType.EAGER, cascade =
  • PSQLException:不能在自动提交模式下使用大对象(PSQLException: Large Objects may not be used in auto-commit mode)
    问题 我正在使用 WildFly 10、Java EE、JPA 和 Hibernate。 最近我将我的应用程序从 MySQL 迁移到 PostgreSQL。 在使用 MySQL 时,我会使用以下方法将图像存储在我的实体中: @Lob @Basic(fetch = FetchType.LAZY) private byte[] image; 这很有效,而且 MySQL 使用LONGBLOB来存储数据。 切换到 PostgreSQL 后,列类型为OID ,并且在持久化图像时收到此错误: Caused by: org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode. at org.postgresql.largeobject.LargeObjectManager.createLO(LargeObjectManager.java:308) at org.postgresql.largeobject.LargeObjectManager.createLO(LargeObjectManager.java:296) at org.postgresql.jdbc.PgPreparedStatement.createBlob(PgPreparedStatement.java:1202)
  • long 类型的错误值:-Postgresql、Hibernate、Spring(bad value for type long: - Postgresql, Hibernate, Spring)
    问题 我想使用 Spring MVC 和 Hibernate 在 PostgresQL 中存储一个实体(一个字符串 + 一个图像)这是我的表。 图像应该是oid的类型。 CREATE TABLE document ( name character varying(200), id serial NOT NULL, content oid, // that should be the image CONSTRAINT document_pkey PRIMARY KEY (id ) ) WITH ( OIDS=FALSE ); 这是我要存储的实体。 @Entity @Table(name = "document") public class Document { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name") private String name; @Column(name="content") private Blob content; //this is the image //getters- setters 你可以看到变量“name”是一个字符串,而不是长整数。
  • Hibernate 和 Java 和 Postgres @Enumerated(value=EnumType.STRING) - 引起:org.postgresql.util.PSQLException:int 类型的错误值(Hibernate and Java and Postgres @Enumerated(value=EnumType.STRING) - Caused by: org.postgresql.util.PSQLException: Bad value for type int)
    问题 我的映射出现异常: @Enumerated(value=EnumType.STRING) public AuthenticationVendor getProvider() { return this.provider; } 这是枚举 public enum AuthenticationVendor { LOCALDB, GOOGLE, FACEBOOK } 异常似乎表明 hibernate 正在使用org.hibernate.type.EnumType$OrdinalEnumValueMapper来获取基于堆栈跟踪的值: Caused by: org.postgresql.util.PSQLException: Bad value for type int : LOCALDB at org.postgresql.jdbc.PgResultSet.toInt(PgResultSet.java:2831) at org.postgresql.jdbc.PgResultSet.getInt(PgResultSet.java:2088) at org.postgresql.jdbc.PgResultSet.getInt(PgResultSet.java:2502) at com.zaxxer.hikari.pool.HikariProxyResultSet.getInt
  • Cause: org.postgresql.util.PSQLException: ERROR: cached plan must not change result type
    引起该报错的原因,都是应用端在修改了数据库字段,或者增减字段后,没有重启应用导致。 场景重现: session 1: hank=> create table test_tbl(id int,name varchar(50)); CREATE TABLE hank=> insert into test_tbl values (1,'hank'),(2,'jecc'),(3,'jully'); INSERT 0 3 hank=> prepare select_test_tbl (character varying) as select * from test_tbl where name=$1; PREPARE hank=> execute select_test_tbl ('hank'); id | name ----+------ 1 | hank (1 row) session 2: hank=> alter table test_tbl add column age int; ALTER TABLE 回到session 1: 报错 hank=> execute select_test_tbl ('hank'); ERROR: cached plan must not change result type 这里解释一下,应用使用prepare语句是为了绑定变量,执行计划重用