-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Result of a named query is always a list of objects
PostPosted: Mon Mar 26, 2012 1:08 pm 
Newbie

Joined: Mon Mar 26, 2012 12:41 pm
Posts: 2
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> ...


Top
 Profile  
 
 Post subject: Re: Result of a named query is always a list of objects
PostPosted: Wed Mar 28, 2012 5:02 am 
Newbie

Joined: Mon Mar 26, 2012 12:41 pm
Posts: 2
previous reply is spam...

I used a differrent approach now:

I work with regular Query's and use a ResultSetTramsformer
(no new entity implemented)

=> works!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.