-->
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: "select new" and collection
PostPosted: Sat Aug 30, 2008 8:16 am 
Beginner
Beginner

Joined: Mon Jan 07, 2008 4:13 am
Posts: 22
Hi!

i have 3 tables : item, sub_item and bid and 3 classes: Item, SubItem and Bid. And ResultItem class as result bean.

I have this select:

Code:
return getHibernateTemplate().find("select new com.app.model.ResultItem(" +
             "item.createDate, item.publishDate, item.finishDate, " +
             "size(item.bids), " +
             "(select max(bid.bidPrice) as max from item.bids bid) " +
             ") from Item item where item.owner = ? " +
             "group by item.id, item.createDate, item.publishDate, item.finishDate", owner);
    }


and in ResultItem class this constructor:

Code:
public ResultItem(Date createDate, Date publishDate, Date finishDate,
          Integer numberOfBids, Double maxBid) {
       this.createDate = createDate;
       this.publishDate = publishDate;
       this.finishDate = finishDate;
       this.numberOfBids = numberOfBids;
       this.maxBid = maxBid;
    }


and everything is OK. BUT, i need add next property of Item (collection):

List subItems (connection to sub_item table):

Code:
return getHibernateTemplate().find("select new com.app.model.ResultItem(" +
             "item.createDate, item.publishDate, item.finishDate, " +
             "item.subItems, " +
             "size(item.bids), " +
             "(select max(bid.bidPrice) as max from item.bids bid) " +
             ") from Item item where item.owner = ? " +
             "group by item.id, item.createDate, item.publishDate, item.finishDate", owner);
    }


and constructor:

Code:
public FreeOfferFreightSearchResultItem(Date createDate, Date publishDate, Date finishDate, List subItems,
          Integer numberOfBids, Double maxBid) {
       this.createDate = createDate;
       this.publishDate = publishDate;
       this.finishDate = finishDate;
       this.numberOfBids = numberOfBids;
       this.maxBid = maxBid;
       this.subItems = subItems;
    }


but, it is not correct, please how can I select simple properites (Integer, Date, ..), count(*) or size(), MAX (or MIN) and collection in ONE select.

error message:

org.springframework.orm.hibernate3.HibernateQueryException: Unable to locate appropriate constructor on class [com.app.model.ResultItem]

thanks!

Ivan


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.