Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > order-by in nam...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 1297 of 1403
Post > Topic >>

order-by in named-query

by Henning Eiben <eiben@[EMAIL PROTECTED] > Mar 12, 2007 at 02:55 PM

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigBEAEE6D33E96361040A606E3
Content-Type: text/plain; charset=ISO-8859-15
Content-Transfer-Encoding: quoted-printable

Hi,

I'm currently developing a small app, based on EJB 3.0. I created a
named query like this:

--- cut --- cut --- cut --- cut ---

@[EMAIL PROTECTED]
(name =3D "topItems", query =3D "select i from Orderitem oi in=
ner
join oi.item i group by i order by sum(oi.quantity) desc")

--- cut --- cut --- cut --- cut ---=09

--- cut --- cut --- cut --- cut ---

public Collection<Item> getTopItems()
{
	Query q =3D em.createNamedQuery("topItems");
	q.setMaxResults(25);
	return (Collection<Item>) q.getResultList();
}

--- cut --- cut --- cut --- cut ---


But this doesn't seem to work like I expect it to work: I get an
exception from the JDBC-driver :( It seems like my database (MySQL)
doesn't like the "sum(oi.quantity)" in the order by clause :(

well, I played with the sql, and it seems like MySQL would prefer
something like this:

--- cut --- cut --- cut --- cut ---

@[EMAIL PROTECTED]
(name =3D "topItems", query =3D "select i, sum(oi.quantity) as=

qty from Orderitem oi inner join oi.item i group by i order by qty desc")=

=09
--- cut --- cut --- cut --- cut ---


But this in turn doesn't seem to work with hibernate, at least I tried
to evaluate this expression in the HQL-Editor, and hibernate could not
create a SQL-statment :(

-=3D-=3D-
=2E.. Black holes suck.


--------------enigBEAEE6D33E96361040A606E3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iQCVAwUBRfVb7tXV+99RZLuBAQJUsQQAmIgMvcmVlEIu3QBrqjXnzgKCxyJjio8r
qCTGawwQyyzT8XaWONxzB0MdHMHpffn8IFNKmX61E/HFeN/KqYqN+OdLycAAgQTl
A3LMPCGsnfC/tyZN7WV7X1GT9wJ+XziIz0RugYbF+Q0MPqMcXWb60nBGmk3QU3BS
LUUy67IXIwo=
=n+uP
-----END PGP SIGNATURE-----

--------------enigBEAEE6D33E96361040A606E3--
 




 1 Posts in Topic:
order-by in named-query
Henning Eiben <eiben@[  2007-03-12 14:55:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 23:52:56 CST 2008.