I am using Hibernate with Seam and JBoss.
I wanna join some tables in order to get some business information.
Therefor I created a new Entity with some NamedQueries:
Code:
@SuppressWarnings("serial")
@Entity
@NamedQueries({
@NamedQuery(name="geschaeftsfall.produkt",
query="select s.referenzId as id, s.dbStatus, s.version, s.speicherdatum, s.gelesen, s.showInTodo, s.status, " +
" prod.id as gfnr, prod.produktInformation as sparte, prod.bruttoprämieProJahr as praemie, " +
" p.nachname || ' ' || p.vorname1 as vnName, " +
" a.postleitzahl || ' ' || a.ort as vnAnschrift " +
" from DBStatus s, DBProdukt prod join prod.versicherungsnehmer p join p.adressen a" +
" where a.hauptanschrift = 1 and s.referenzId = prod.id and" +
" s.objektTyp = 1 and s.showInTodo = 1"),
@NamedQuery(name="geschaeftsfall.schadenmeldung",
query="select s.referenzId as id, s.dbStatus, s.version, s.speicherdatum, s.gelesen, s.showInTodo, s.status, " +
" sm.id as gfnr, sm.schadenMeldungSparte as sparte, '' as praemie, " +
" p.nachname || ' ' || p.vorname1 as vnName, " +
" a.postleitzahl || ' ' || a.ort as vnAnschrift " +
" from DBStatus s, DBSchadenmeldung sm join sm.versicherungsnehmer p join p.adressen a" +
" where a.hauptanschrift = 1 and s.referenzId = sm.id and" +
" s.objektTyp = 1 and s.showInTodo = 1"),
})
public class DBGeschaeftsfall {
...}
For every field there is a corresponding attribute in the class "DBGeschaeftsfall" which I did cut off to make the message shorter. (P.s: sorry about the fields being German)
In components.xml I added the entity to my mapping classes:
Code:
<persistence:mapping-classes>
[...]
<value>com.generali.fipos.persistence.db.complex.DBGeschaeftsfall</value>
</persistence:mapping-classes>
In my Data Access Object I am executing the query
Code:
session = HibernateSessionFactory.getSessionFactory().openSession()
Query query = session.getNamedQuery("geschaeftsfall.produkt")
List<DBGeschaeftsfall> beratungen = query.list();
The query itself works, but the result is always a List<Object> instead of a List<DBGeschaeftsfall> (and I will get a ClassCastException later when iterating over the list)
What am I doing wrong. I'd really appreciate a List<DBGeschaeftsfall> ...