Всем доброго времени суток, помогите пожалуйста разобраться с возникшей ошибкой: org.hibernate.exception.GenericJDBCException: Недопустимое имя столбца
Сам запрос выглядит так :
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
String sql = "select nkl,psum,lsum,ltl,tzav, lth,dv, dn,nv,nvp from"+
"(select nkl,psum,lsum,ltl, tzav, lth,dv, dn ,nv,nvp from"+
"(select nkl, tzav, psum,lsum,ltl, lth, dv, dn,nv,nvp from"+
"(select nkl, tzav, psum,lsum,ltl, lth, ROUND(Diam,2) dv, ROUND(Ddiam,2) dn,nv,nvp from zxp.valpr"+
" where (nkl,tzav) in (select nkl,MAX(tzav) from zxp.valpr where tviv is null and pvn=0 and rop=0 group by nkl ) and pvn=0 and rop=0)))order by 1";
SQLQuery query = session.createSQLQuery(sql);
//query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
query.addEntity(workval.class);
List res = query.list();
request.getRequestDispatcher("4kl/test.jsp").forward(request, response);
session.getTransaction().commit();
workval.java:
package four_mill;
import java.io.Serializable;
import java.util.Date;
public class workval implements Serializable {
private static final long serialVersionUID = 1L;
private Integer nkl;
private Integer ukey;
private Integer psum;
private Integer lsum;
private Integer ltl;
private Date tzav;
private Date tviv;
private Integer lth;
private Integer dv;
private Integer dn;
private Integer nv;
private Integer nvp;
private Integer pvn;
private Integer rop;
public workval(Integer nkl, Integer ukey, Integer psum, Integer lsum, Integer ltl, Integer lth,
Integer dv, Integer dn, Integer nv, Integer nvp,Integer pvn,Integer rop, Date tzav, Date tviv) {
this.nkl = nkl;
this.ukey = ukey;
this.psum = psum;
this.lsum = lsum;
this.ltl = ltl;
this.lth = lth;
this.dv = dv;
this.dn = dn;
this.nv = nv;
this.nvp = nvp;
this.pvn = pvn;
this.rop = rop;
this.tzav = tzav;
this.tviv = tviv;
}
public workval(){
}
public Integer getNkl() {
return nkl;
}
public void setNkl(Integer nkl) {
this.nkl = nkl;
}
public Integer getUkey() {
return ukey;
}
public void setUkey(Integer ukey) {
this.ukey = ukey;
}
public Integer getPsum() {
return psum;
}
public void setPsum(Integer psum) {
this.psum = psum;
}
public Integer getLsum() {
return lsum;
}
public void setLsum(Integer lsum) {
this.lsum = lsum;
}
public Integer getLtl() {
return ltl;
}
public void setLtl(Integer ltl) {
this.ltl = ltl;
}
public Date getTzav() {
return tzav;
}
public void setTzav(Date tzav) {
this.tzav = tzav;
}
public Date getTviv() {
return tviv;
}
public void setTviv(Date tviv) {
this.tviv = tviv;
}
public Integer getLth() {
return lth;
}
public void setLth(Integer lth) {
this.lth = lth;
}
public Integer getDv() {
return dv;
}
public void setDv(Integer dv) {
this.dv = dv;
}
public Integer getDn() {
return dn;
}
public void setDn(Integer dn) {
this.dn = dn;
}
public Integer getNv() {
return nv;
}
public void setNv(Integer nv) {
this.nv = nv;
}
public Integer getNvp() {
return nvp;
}
public void setNvp(Integer nvp) {
this.nvp = nvp;
}
public Integer getPvn() {
return pvn;
}
public void setPvn(Integer pvn) {
this.pvn = pvn;
}
public Integer getRop() {
return rop;
}
public void setRop(Integer rop) {
this.rop = rop;
}
}
workv.hbm.xml
<?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>
<class name="four_mill.workval" table="valpr" catalog="ZXP">
<id name="ukey" type="java.lang.Integer">
<column name="UKEY" />
<generator class="increment" />
</id>
<property name="nkl" type="java.lang.Integer">
<column name="NKL" not-null="false" unique="true" />
</property>
<property name="psum" type="java.lang.Integer">
<column name="PSUM" not-null="false" unique="true" />
</property>
<property name="lsum" type="java.lang.Integer">
<column name="LSUM" not-null="false" unique="true" />
</property>
<property name="ltl" type="java.lang.Integer">
<column name="LTL" not-null="false" unique="true" />
</property>
<property name="lth" type="java.lang.Integer">
<column name="LTH" not-null="false" unique="true" />
</property>
<property name="dv" type="java.lang.Integer">
<column name="DV" not-null="false" unique="true" />
</property>
<property name="dn" type="java.lang.Integer">
<column name="DN" not-null="false" unique="true" />
</property>
<property name="nv" type="java.lang.Integer">
<column name="NV" not-null="false" unique="true" />
</property>
<property name="nvp" type="java.lang.Integer">
<column name="NVP" not-null="false" unique="true" />
</property>
<property name="pvn" type="java.lang.Integer">
<column name="PVN" not-null="false" unique="true" />
</property>
<property name="rop" type="java.lang.Integer">
<column name="ROP" not-null="false" unique="true" />
</property>
<property name="tzav" type="date">
<column name="TZAV" not-null="false" unique="true" />
</property>
<property name="tviv" type="date">
<column name="TVIV" not-null="false" unique="true" />
</property>
</class>
</hibernate-mapping>
В чем может быть проблема ? Всем большое спасибо за помощь, и совет.
Если сделать запрос на выборку всех данных в БД ошибка таже
String sql = "select * from zxp.valpr";
Добился вывода при Select * from zxp.valpr Ошибкой было, да это даже ошибкой не назовеш :
ROUND(Diam,2) dv, ROUND(Ddiam,2) dn
В базе есть стобцы Diam и Ddiam но нет dv и dn. Заменив имена и конфиг hbm Ошибка при выполнении моего основного запроса осталась прежней. Неужели Hibernate настолько вредный в использовании ? может отказаться от данного фреймворка ? Посоветуйте как быть, запросы с БД для моего проекта главная задача, а тут такие неприятные нюансы, незнаю как быть ?
Упрастил запрос, проблема не решена:
String sqll = "select nkl, tzav, psum,lsum,ltl, lth, diam, ddiam,nv,nvp from zxp.valpr where (nkl,tzav) in (select nkl,MAX(tzav) from zxp.valpr where tviv is null and pvn=0 and rop=0 group by nkl ) and pvn=0 and rop=0 order by 1";