hi,
I have problem with mapping. I recive fallowing error :
Code:
Exception in thread "main" java.lang.ClassCastException: org.hibernate.impl.QueryImpl cannot be cast to javax.management.Query
at de.elaser.handwerk2008.DAO.BelegposDAO.get(BelegposDAO.java:20)
at Main.main(Main.java:10)
here are my classes and mappin files:
Code:
import org.hsqldb.types.Binary;
public class Belegpos {
private int id;
private String belegid;
private int zeile;
private String oz;
private String postyp;
private String wg;
private String artnr;
private float menge;
private String kurz;
private Binary lang;
private float epreis;
private float vpreis;
private int steuer;
private String me;
private int pe;
private int rabattpos;
Belegpos(){}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBelegid() {
return belegid;
}
public void setBelegid(String belegid) {
this.belegid = belegid;
}
public int getZeile() {
return zeile;
}
public void setZeile(int zeile) {
this.zeile = zeile;
}
public String getOz() {
return oz;
}
public void setOz(String oz) {
this.oz = oz;
}
public String getPostyp() {
return postyp;
}
public void setPostyp(String postyp) {
this.postyp = postyp;
}
public String getWg() {
return wg;
}
public void setWg(String wg) {
this.wg = wg;
}
public String getArtnr() {
return artnr;
}
public void setArtnr(String artnr) {
this.artnr = artnr;
}
public float getMenge() {
return menge;
}
public void setMenge(float menge) {
this.menge = menge;
}
public String getKurz() {
return kurz;
}
public void setKurz(String kurz) {
this.kurz = kurz;
}
public Binary getLang() {
return lang;
}
public void setLang(Binary lang) {
this.lang = lang;
}
public float getEpreis() {
return epreis;
}
public void setEpreis(float epreis) {
this.epreis = epreis;
}
public float getVpreis() {
return vpreis;
}
public void setVpreis(float vpreis) {
this.vpreis = vpreis;
}
public int getSteuer() {
return steuer;
}
public void setSteuer(int steuer) {
this.steuer = steuer;
}
public String getMe() {
return me;
}
public void setMe(String me) {
this.me = me;
}
public int getPe() {
return pe;
}
public void setPe(int pe) {
this.pe = pe;
}
public int getRabattpos() {
return rabattpos;
}
public void setRabattpos(int rabattpos) {
this.rabattpos = rabattpos;
}
}
package de.elaser.handwerk2008.DAO;
import javax.management.Query;
import org.hibernate.HibernateException;
import de.elaser.handwerk.HWException.HWException;
import de.elaser.handwerk2008.model.Belegpos;;
public class BelegposDAO extends DAO{
public BelegposDAO(){}
public Belegpos get()
throws HWException{
try{
begin();
Query q=(Query) getSession().createQuery("from Belegpos ");
//((org.hibernate.Query) q).setString("belegid", belegID);
Belegpos belpos=(Belegpos)((org.hibernate.Query) q).uniqueResult();
commit();
return belpos;
}
catch(HibernateException e){
rollback();
throw new HWException("no result",e);
}
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="de.elaser.handwerk2008.model">
<class
name="Belegpos"
table="belegpos"
>
<meta attribute="sync-DAO">false</meta>
<id
name="id"
type="integer"
column="id"
>
<generator class="native"/>
</id>
<property
name="belegid"
column="belegid"
type="string"
not-null="true"
length="8"
/>
<property
name="zeile"
column="zeile"
type="integer"
not-null="true"
length="10"
/>
<property
name="oz"
column="oz"
type="string"
not-null="false"
length="15"
/>
<property
name="postyp"
column="postyp"
type="string"
not-null="false"
length="3"
/>
<property
name="wg"
column="wg"
type="string"
not-null="false"
length="3"
/>
<property
name="artnr"
column="artnr"
type="string"
not-null="false"
length="25"
/>
<property
name="menge"
column="menge"
type="java.lang.Float"
not-null="false"
length="12"
/>
<property
name="kurz"
column="kurz"
type="string"
not-null="false"
length="255"
/>
<property
name="lang"
column="lang"
type="binary"
not-null="false"
/>
<property
name="epreis"
column="epreis"
type="java.lang.Float"
not-null="false"
length="12"
/>
<property
name="vpreis"
column="vpreis"
type="java.lang.Float"
not-null="false"
length="12"
/>
<property
name="steuer"
column="steuer"
type="integer"
not-null="false"
length="10"
/>
<property
name="me"
column="me"
type="string"
not-null="false"
length="6"
/>
<property
name="pe"
column="pe"
type="integer"
not-null="false"
length="10"
/>
<property
name="rabattpos"
column="rabattpos"
type="integer"
not-null="false"
length="10"
/>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://test-server/Elaser</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<!-- property name="hibernate.connection.pool_size"></property -->
<!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="de\elaser\handwerk2008\model\Belegpos.hbm.xml"/>
</session-factory>
</hibernate-configuration>
thanks for your help!