-->
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.  [ 8 posts ] 
Author Message
 Post subject: Project sum (qty*price) don't work
PostPosted: Wed May 11, 2005 11:21 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Hibernate version:3.03
Hi,
why Hiberbnate return me this error
org.hibernate.QueryException: could not resolve property: qtavdi*vo.qtavdi of: vo.as400.CVenditaVO

Can you help me please?
Devis

Code:
Session session = AS400Session.currentSession();
      Criteria crit = session.createCriteria(CVenditaVO.class, "vo")
          .add(Restrictions.eq("pk.shopdi", shop))
          .add(Restrictions.eq("pk.datadi", java.sql.Date.valueOf(data)))
          .createCriteria("modevo")
          .createCriteria("cmpfmo", "cmp")
          .add(Restrictions.eq("cmp.cdc_cmpf", cdc_cat))
          .setProjection(Projections.projectionList()
                         .add(Projections.groupProperty("vo.modedi").as(
          "modedi"))
                         .add(Projections.sum("vo.qtavdi").as("qtavdi"))
                         .add(Projections.sum("vo.qtavdi*vo.qtavdi").as("pvendi"))
                         )
          .setCacheable(true)
          .addOrder(Order.desc("qtavdi"))
          .setResultTransformer(new AliasToBeanResultTransformer(CVenditaVO.class));


[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 11:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Seems simple enough: [qtavdi*vo.qtavdi] is *not* a property of your CVenditaVO class. Check the javadocs for projections again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 12:01 pm 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Thanks Steve for your replay,

but
"
Seems simple enough: [qtavdi*vo.qtavdi] is *not* a property "
yes is not property of my CVenditaVO class but
i wish that Hibernate sum(qty*price) and the "result" will be push into
my alias "pvendi".

add(Projections.sum("vo.qtavdi*vo.pvendi").as("totaldi"))

Totaldi is CvenditaVO property.
Have some idea please.
In my hql i have used this
Code:
          "Select sum(ay.qtavdi*ay.pvendi)as totaldi from CVenditaVO ay where ay.pk.shopdi=? and ay.pk.datadi=?");


but now i love the new CriteriaApi and i wish to use it, can you help me
please
Devis


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 12:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
AFAIK, you'd currently have to use Projections.sqlProjection().


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 1:01 pm 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Ok thank's,
but i think, if you can look this bit code, will be useful can use
" .add(Projections.sum("vo.qtavdi*vo.pvendi").as("pvendi"))",
and i will confirm you that hibernate trhows this exception.
Ok i hope to use Projections.sum.
Devis

Code:
org.hibernate.QueryException: could not resolve property: qtavdi*vo.pvendi of: vo.as400.CVenditaVO

   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)

   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)

   at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)

   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getType(CriteriaQueryTranslator.java:442)

   at org.hibernate.criterion.AggregateProjection.getTypes(AggregateProjection.java:28)

   at org.hibernate.criterion.AliasedProjection.getTypes(AliasedProjection.java:37)

   at org.hibernate.criterion.ProjectionList.getTypes(ProjectionList.java:38)

   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:297)

   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:79)

   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1297)

   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)

   at org.hibernate.impl.CriteriaImpl$Subcriteria.list(CriteriaImpl.java:141)



Code:
      Session session = AS400Session.currentSession();
      Criteria crit = session.createCriteria(CVenditaVO.class, "vo")
          .add(Restrictions.eq("pk.shopdi", shop))
          .add(Restrictions.eq("pk.datadi", java.sql.Date.valueOf(data)))
          .createCriteria("modevo")
          .createCriteria("cmpfmo", "cmp")
          .add(Restrictions.eq("cmp.cdc_cmpf", cdc_cat))
          .setProjection(Projections.projectionList()
                         .add(Projections.groupProperty("vo.modedi").as(
          "modedi"))
                         .add(Projections.sum("vo.qtavdi").as("qtavdi"))
                         .add(Projections.sum("vo.qtavdi*vo.pvendi").as("pvendi"))

                         )
          .setCacheable(true)
          .addOrder(Order.desc("qtavdi"))
          .setResultTransformer(new AliasToBeanResultTransformer(CVenditaVO.class));



Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 1:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
AFAIK, you'd currently have to use Projections.sqlProjection().


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 1:54 pm 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Ok,
but in the forum and internet examples don't exists? my code don't work
can you help me
Devis
Code:

      String s[]=new String[1];
      s[0]="pvendi";
    ??? type ??? double i wish.


     
      Criteria crit = session.createCriteria(CVenditaVO.class, "vo")
          .add(Restrictions.eq("pk.shopdi", shop))
          .add(Restrictions.eq("pk.datadi", java.sql.Date.valueOf(data)))
          .createCriteria("modevo")
          .createCriteria("cmpfmo", "cmp")
          .add(Restrictions.eq("cmp.cdc_cmpf", cdc_cat))
          .setProjection(Projections.projectionList()
                         .add(Projections.groupProperty("vo.modedi").as(
          "modedi"))
                         .add(Projections.sum("vo.qtavdi").as("qtavdi"))
                         .add(Projections.avg("vo.pvendi").as("pvendi"))
                         .add(Projections.sqlProjection("sum(vo.pvendi*vo.qtavdi)",s,?????))
                         )



Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 2:03 pm 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Ok Steve, work,
here code thank you very much.
Devis
Code:


      Criteria crit = session.createCriteria(CVenditaVO.class, "vo")
          .add(Restrictions.eq("pk.shopdi", shop))
          .add(Restrictions.eq("pk.datadi", java.sql.Date.valueOf(data)))
          .createCriteria("modevo")
          .createCriteria("cmpfmo", "cmp")
          .add(Restrictions.eq("cmp.cdc_cmpf", cdc_cat))
          .setProjection(Projections.projectionList()
                         .add(Projections.groupProperty("vo.modedi").as(
          "modedi"))
                         .add(Projections.sum("vo.qtavdi").as("qtavdi"))
                         .add(Projections.sqlProjection(
          "sum(pvendi*qtavdi)as pvendi",
          new String[] {"pvendi"}
          ,
          new Type[] {Hibernate.DOUBLE}
          ))

                         )
          .setCacheable(true)
          .addOrder(Order.desc("qtavdi"))
          .setResultTransformer(new AliasToBeanResultTransformer(CVenditaVO.class));



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.