could not read column value from result set: MEDFAC1_14_0_; Invalid column name SQL Error: 17006, SQLState: null

Description

The following is my section of hibernate mapping file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="gov.njdhss.hippocrates.ems.valueobjects">
<class name="HeprEmsMedfacFacilityVO" table="HEPR_MEDFAC">
<id name="medfacId" column="MEDFAC_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">HEPR_MEDFAC_SEQ</param>
</generator>
</id>

<property name="medfacName" type="java.lang.String"
column="MEDFAC_NAME" update="true" insert="true">
</property>
<property name="facCode" type="java.lang.String"
column="FAC_CODE" update="true" insert="true">
</property>

</class>

<sql-query name="allfacility">
<return alias="facilities" class="HeprEmsMedfacFacilityVO" >
<return-property name="medfacName" column="MEDFAC_NAME"/>
</return>
<![CDATA[
select facilities.MEDFAC_NAME AS medfacName
from HEPR_MEDFAC facilities
]]>
</sql-query>
</hibernate-mapping>

I am trying to execute the query using the following client code:

public List getAllFacility() {

List listAllFacilities = null;

listAllFacilities = getHibernateTemplate().findByNamedQuery(
"allfacility");

return listAllFacilities;

}

The following is the error:

Hibernate:
select
facilities.MEDFAC_NAME AS medfacName
from
HEPR_MEDFAC facilities

  • could not read column value from result set: MEDFAC1_14_0_; Invalid column name

  • SQL Error: 17006, SQLState: null

  • Invalid column name

  • Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]

  • SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]

Any idea if it is a bug or there is any error in my code.

Activity

Aaron PauOctober 12, 2016 at 6:48 PM

Although this issue persists, this is my workaround that allows SQL queries to return a limited subset of data fields. Simply put, it requires adding a separate hibernate class definition for each unique set of query result fields, but does NOT require separate Java classes to be defined. Steps:
1. Define a separate hibernate class mapping against the original Java class, listing only those fields that are returned from the limited query. Value the "entity-name" attribute with a unique pseudonym.
2. When defining the "sql-query", refer to the pseudonym from the "return" element, rather than using the original class name.
3. Map those fields normally (e.g. via return-property or as {}), only listing those fields in the pseudonym class
Example hibernate mapping:
<class name="com.test.MyClass" entity-name="com.test.MyClassPseudonym">...</class>
<sql-query name="MyQuery"><return alias="mc" class="com.test.MyClassPseudonym">/>...</sql-query>

Brett MeyerJuly 8, 2014 at 3:10 PM

Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!

Brett MeyerApril 7, 2014 at 5:44 PM

In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.

If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.

Thank you!

RachitMay 4, 2009 at 12:50 PM

Hi,

I too have stuck on the issue. I am @SqlResultSetMapping annotation to achieve the same. If somebody has a quick fix other than retrieving all columns, reply me.

-Thanks

Rachit

Sergio EduardoMarch 5, 2009 at 11:56 PM

I've stopped on same BUG...

I need a sql-query that returns only some properties of an entity.

my hibernate-mapping :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="br.gov.bcb.rdr.persistencia.vo">
<class name="RankingQuantidadeVO" table="RPR_RANKING_PROVISORIO">
<id column="RPR_ID" name="id">
<generator class="native"></generator>
</id>
<property name="mesAno" column="RPR_DT"></property>
<property name="obsReclamacao" column="RPR_DS_OBS_RECLAMACAO"></property>
<property name="obsCliente" column="RPR_DS_OBS_CLIENTES"></property>
<property name="qtdClientes" column="RPR_QT_CLIENTES"></property>
<property name="qtdReclamacoes" column="RPR_QT_RECLAMACOES"></property>
<property name="qtdSolucionadas" column="RPR_QT_RECLAMA_SOLUCIONADAS"></property>
<property name="qtdImprocedente" column="RPR_QT_RECLAMA_IMPROCED_SOLUC"></property>
<property name="qtdEncaminhada" column="RPR_QT_RECLAMA_ENCAMINHADAS"></property>
<property name="qtdDenuncias" column="RPR_QT_DENUNCIAS"></property>
<property name="idPessoaBC" column="IFR_ID_PESSOA_BC"></property>
<property name="idConglomerado" column="COR_ID"></property>
<many-to-one name="usuarioVO" class="UsuarioVO" column="URR_ID"></many-to-one>
</class>
<sql-query name="rankingquantidade.select.quantidade.ranking">
<return alias="rnq" class="RankingQuantidadeVO">
<return-property name="idPessoaBC" column="IFR_ID_PESSOA_BC" />
<return-property name="idConglomerado" column="COR_ID" />
<return-property name="qtdReclamacoes" column="QNT_REGISTROS" />
<return-property name="id" column="RPR_ID" />
</return>
<![CDATA[
select
IFR_ID_PESSOA_BC,
COR_ID,
QNT_REGISTROS,
RPR_ID,
from
RPR_RANKING_PROVISORIO
]]>
</sql-query>
</hibernate-mapping>

and the problem is:

Hibernate tries to look all properties of a mapped class in resultSet generated.
My sql query, brought only 4 properties, but hibernate tried to acess all properties alias (from resultSet ) and of course, the same error happened 'cause the query must not
bring all fields.

I've looked the hibernate-core 3.2.6 source code and the problem occurs in the method org.hibernate.persister.entity.AbstractEntityPersister # hydrate

To temporary solve this problem, you should return all mapped properties of your entity in your custom SQL Query for loading...

If someone knows any better solution, please post it...

Rejected

Details

Assignee

Reporter

Affects versions

Priority

Created December 28, 2007 at 6:46 PM
Updated October 12, 2016 at 6:48 PM
Resolved July 8, 2014 at 3:10 PM

Flag notifications