I'm working together with treklipper on this and we have now tried the following:
Quote:
Query query = session.createQuery("select t.tittel from net.esimulation.db.innboksovelse.InnboksOppgave t");
I could then iterate through the results the following way:
Code:
List l = query.list();
java.util.Iterator i = l.iterator();
while(i.hasNext()) {
System.out.println(i.next());
}
So far so good..
When trying to get two columns from the table, the result is wrapped in an object. But what kind of object is this? When casting to the object it is mapped to, I get a ClassCastException.
Code:
Query query = session.createQuery("select t.tittel,t.innboksOppgaveID from net.esimulation.db.innboksovelse.InnboksOppgave t");
List l = query.list();
java.util.Iterator i = l.iterator();
while(i.hasNext()) {
InnboksOppgave o = (InnboksOppgave)i.next(); // Exception HERE!
System.out.println(o.getinnboksOppgaveID() + " " + o.gettittel());
}
So what kind of object is this? Is it not possible to cast without having all the columns?
Are we missing anything in our mapping file?
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping >
<class name="net.esimulation.db.innboksovelse.InnboksOppgave" table="innboksOppgaver" >
<id name="innboksOppgaveID" column="innboksOppgaveID" type="int" unsaved-value="0">
<generator class="identity"/>
</id>
<property name="innboksOvelseID" column="innboksOvelseID" type="int" />
<property name="tittel" column="tittel" type="java.lang.String" />
<property name="hovedtekst" column="hovedtekst" type="java.lang.String" />
<property name="fraPerson" column="fraPerson" type="java.lang.String" />
<property name="oppgaveDato" column="oppgaveDato" type="java.util.Date" />
<property name="anbefaltTekst" column="anbefaltTekst" type="java.lang.String" />
<property name="anbefaltGrupperingID" column="anbefaltGrupperingID" type="int" />
<property name="anbefaltHurtighet" column="anbefaltHurtighet" type="int" />
<property name="anbefaltViktighet" column="anbefaltViktighet" type="int" />
</class>
</hibernate-mapping>
[/quote]