dakujem, to je ono, new MyResultBean(...) a k tomu prislusny konstruktor.
ale neviem preco mi tam funguju len jednoduche typy, ako napr. Integer,
Date.
napr. konstruktor:
MyResultBean(Integer i1, Date d1) a pouzijem:
select new com.aplikacia.model.MyResultBean(item.c, item.createDate) je
vsetko OK, ale ak pouzijem
MyResultBean(Integer i1, Date d1, List<Bid> bids)
a
select new com.aplikacia.model.MyResultBean(item.c, item.createDate,
item.bids)
vypisuje Unable to locate appropriate constructor on class
[com.aplikacia.model.MyResultBean] napriek tomu ze dany konstruktor mam.
Ivan
Lukas Barton wrote / napísal(a):
Ahoj,
select* new cz.java.ItemStatBean(*item.createDate, size(item.bids),
(select max(bid.bidPrice) from item.bids bid)*)* from Item ...
Lukas
Ivan Polák napsal(a):
dakujem za rady, da sa povedat ze vsetky som pouzil :-)
vysledok:
getHibernateTemplate().find("select item.createDate, size(item.bids),
" +
"(select max(bid.bidPrice) from item.bids bid) " +
"from Item item where item.owner = ? group by item.id,
item.createDate", owner);
teda ako radil Lukas spravil som manapovanu kolekciu bids v item.
mam ale doplnujucu otazku, ako potom takyto vysledok namapovavate na
bean, ako sa by sa spravne mal namapovat vysledok kde sa vracia napr.
max, min, avg a podobne.
vsetkym dakujem!
Ivan
Lukas Barton wrote / napísal(a):
Napr.:
select max(bid.bidPrice),count(bid.id) from Bid bid group by
bid.item.id
Zajimavejsi zapis bude, kdyz ma Item mapovanou kolekci bids (ale
neznam vase UC, tak nevim, zda je to rozumne):
a) select max(bid.bidPrice), count(bid.id) from Item item join
item.bids bid group by item.id
b) select sizeof(item.bids), (select max(bid.bidPrice) from
item.bids bid) from Item item
Dalsi moznosti vymyslet podle
http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html sam.
Lukas
Ivan Polák napsal(a):
Zdravim konferenciu,
mozete mi pomoct prepisat tento select do hibernate query:
select max(b.bid_price), count(*)
from item f
join bid b on b.fk_item_id = f.id
where f.id = 10
group by f.id
triedy su Item a Bid, Item ma : id a Bid ma id, bidPrice a itemId
(pre fk_item_id).
dakujem
Ivan