Hello,
When I try to execute the query below (to return the top most sold books)
String qry = "select l, sum(venda.quantidade) " +
"from Livro l " +
"group by l.codigo " +
"order by sum(venda.quantidade) ";
Hibernate generates this:
Hibernate: select livro0_.cd_livro as cd_livro, livro0_.nm_livro as nm_livro, livro0_.ds_notas as ds_notas, livro0_.vr_preco as vr_preco, livro0_.dt_publicacao as dt_publi5_, livro0_.cd_tipo as cd_tipo from livro livro0_ group by livro0_.cd_livro order by sum(venda.quantidade)
That is a wrong query!
How can I do that?? :-(
Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="bean.Livro"
table="livro"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="codigo"
column="cd_livro"
type="int"
>
<generator class="hilo">
<param name="table">nrAutor</param>
<param name="column">next_value</param>
</generator>
</id>
<property
name="nome"
type="java.lang.String"
update="true"
insert="true"
column="nm_livro"
/>
<property
name="notas"
type="java.lang.String"
update="true"
insert="true"
column="ds_notas"
/>
<property
name="preco"
type="java.math.BigDecimal"
update="true"
insert="true"
column="vr_preco"
/>
<property
name="publicacao"
type="java.util.Date"
update="true"
insert="true"
column="dt_publicacao"
/>
<many-to-one
name="tipoLivro"
class="bean.TipoLivro"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="cd_tipo"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Livro.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Quote:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="bean.Livro"
table="livro"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="codigo"
column="cd_livro"
type="int"
>
<generator class="hilo">
<param name="table">nrAutor</param>
<param name="column">next_value</param>
</generator>
</id>
<property
name="nome"
type="java.lang.String"
update="true"
insert="true"
column="nm_livro"
/>
<property
name="notas"
type="java.lang.String"
update="true"
insert="true"
column="ds_notas"
/>
<property
name="preco"
type="java.math.BigDecimal"
update="true"
insert="true"
column="vr_preco"
/>
<property
name="publicacao"
type="java.util.Date"
update="true"
insert="true"
column="dt_publicacao"
/>
<many-to-one
name="tipoLivro"
class="bean.TipoLivro"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="cd_tipo"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Livro.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>