-->
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.  [ 1 post ] 
Author Message
 Post subject: Use Hibernate’s Custom Loaders to fake an aggregation view
PostPosted: Sat Oct 16, 2010 8:11 am 
Newbie

Joined: Sat Oct 16, 2010 7:57 am
Posts: 1
Hi all,
following the article [url=Use Hibernate’s Custom Loaders to fake an aggregation view]http://www.cereslogic.com/pages/2008/06/23/use-hibernates-custom-loaders-to-fake/[/url] i'm trying to make work my "fake view".

Here's my code: (the property names are in Italian, but their meaning is not 'important)
Code:
@javax.persistence.Entity
@Entity(dynamicInsert=false, dynamicUpdate=false, mutable=false)
@Loader(namedQuery="loadArticoloView")
@SqlResultSetMapping(name="loadArticoloView",
                     entities=@EntityResult(entityClass=ArticoloView.class))
@NamedNativeQuery(name="loadArticoloView",
                  query="select " +
                        "a.id as id, nome, descrizione, posizione, prezzo, coefficientePrezzo, prezzoFinito, " +
                        "c.testo as categoria, " +
                        "m.quantita as quantita, " +
                        "(select nome" +
                        "from " +
                        "articolo_fattura " +
                        "left join fornitore on articolo_fattura.id_fornitore = fornitore.id " +
                        "where id_articolo = a.id " +
                        "order by data_fattura DESC " +
                        "limit 0,1) as fornitore " +
                        "from " +
                        "articolo a " +
                        "left join codcategoria c on c.id = a.id_categoria " +
                        "left join magazzino m on m.id_articolo = a.id " +
                        "where a.id = ?",
                        resultSetMapping="loadArticoloView")
public class ArticoloView {
   String id;
   String nome;
   String descrizione;
   String posizione;
   Float prezzo;
   Float coefficientePrezzo;
   Float prezzoFinito;
   String categoria;
   Integer quantita;
   String fornitore;
   
   
   @Id
   public String getId() {
      return id;
   }
   public void setId(String id) {
      this.id = id;
   }   
   
        // getter and setter...
   
}


and i'm trying to do this:
Code:
Query q = em.createQuery("Select count(*) from ArticoloView", Long.class);
System.out.println(q.getResultList().get(0).toString());


hibernate instead execute this query :
Code:
select count(*) as col_0_0_ from ArticoloView articolovi0_

and seem to ignore mine.

in the console outpout i've found : (I do not know if it means something)
Code:
1621 [http-8080-2] INFO org.hibernate.cfg.AnnotationBinder - Binding entity from annotated class: com.example.testhibernate3.hibernate.view.ArticoloView
1624 [http-8080-2] INFO org.hibernate.cfg.annotations.QueryBinder - Binding named native query: loadArticoloView => select a.id as id, nome, descrizione, posizione, prezzo, coefficientePrezzo, prezzoFinito, c.testo as categoria, m.quantita as quantita, (select nomefrom articolo_fattura left join fornitore on articolo_fattura.id_fornitore = fornitore.id where id_articolo = a.id order by data_fattura DESC limit 0,1) as fornitore from articolo a left join codcategoria c on c.id = a.id_categoria left join magazzino m on m.id_articolo = a.id where a.id = ?
1625 [http-8080-2] INFO org.hibernate.cfg.annotations.EntityBinder - Bind entity com.example.testhibernate3.hibernate.view.ArticoloView on table ArticoloView


Someone know where's my error ?


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

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.