1
I am having a difficulty in my system where SQL with Hibernate can not find a specific column by Java, the same query returns the right result when rotated by SQL. IDE used is Netbeans.
The query is the following:
SELECT DE_CONTEUDO FROM ASP.PDI_EMAIL_MODELO WHERE CD_EMAIL_MODELO = 1;
When run by Java and Hibernate the program issues the following error:
Parâmetro inválido: nome de coluna desconhecido CD_EMAIL_MODELO. ERRORCODE=-4460, SQLSTATE=null
The Java method is this:
public List pesquisar(){
String sql = "SELECT DE_CONTEUDO FROM ASP.PDI_EMAIL_MODELO WHERE CD_EMAIL_MODELO = 1";
Session session = HibernateUtil.open();
List query = session.createSQLQuery(sql).addEntity(EmailModelo.class).list();
session.close();
return query;
}
The Entity is as follows:
@Entity
@Table(name = "ASP.PDI_EMAIL_MODELO")
public class EmailModelo implements Serializable {
@Id
@Column(name = "CD_EMAIL_MODELO")
private long cdEmailModelo;
@Column(name = "DE_CONTEUDO")
private String conteudo;
// Getters e setters simples ...
}
And Hibernate.cfg is mapped this way:
<mapping class="persistencia.EmailModelo"/>
Additional details:
- Searches with non-existent rows in the table return an empty list without error in the program. Ex: CD_EMAIL_MODELO = 20
- I’ve had problems with querys in this IDE that the solution was to literally write the same query in low box but tried this case and did not solve
Which database are you using? Which driver are you using to connect to the database?
– Dherik
The database is the IBM DB2 and the driver is the 'IBM DB2 Universal Driver'
– narcizo
What version of Hibernate? What version of the driver are you using? There are problems reading the column names related to the version of Hibernate and the connection driver for Db2 in a combination of older versions of both
– Dherik