Olá pessoal,
Tenho um mapeamento muitos para um e preciso retornar apenas alguns campos. Com o mapeamento que estou fazendo ele executa select em todos os campos, segue as classes, mapeamentos e select gerado…
Muito Obrigado desde já!
//POJO
public class ExiCargo implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 3835538178445863581L;
// Fields
private Integer pkExiCargo;
private Date timestamp;
private Integer fkElemento;
private Integer fkCargo;
private Cargo cargo;
private Elemento elemento;
// Constructors
public Cargo getCargo() {
return cargo;
}
public void setCargo(Cargo cargo) {
this.cargo = cargo;
}
public Elemento getElemento() {
return elemento;
}
public void setElemento(Elemento elemento) {
this.elemento = elemento;
}
/** default constructor */
public ExiCargo() {
}
/** full constructor */
public ExiCargo(Integer fkElemento, Integer fkCargo) {
this.fkElemento = fkElemento;
this.fkCargo = fkCargo;
}
// Property accessors
public Integer getPkExiCargo() {
return this.pkExiCargo;
}
public void setPkExiCargo(Integer pkExiCargo) {
this.pkExiCargo = pkExiCargo;
}
public Date getTimestamp() {
return this.timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public Integer getFkElemento() {
return this.fkElemento;
}
public void setFkElemento(Integer fkElemento) {
this.fkElemento = fkElemento;
}
public Integer getFkCargo() {
return this.fkCargo;
}
public void setFkCargo(Integer fkCargo) {
this.fkCargo = fkCargo;
}
}
//MAPEAMENTO
<?xml version=“1.0”?>
<!DOCTYPE hibernate-mapping PUBLIC “-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>
<!-- Generated 07/08/2006 08:48:12 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name=“br.com.shc.teste.relacionado.ExiCargo” table=“exicargo”>
<comment></comment>
<id name=“pkExiCargo” type=“java.lang.Integer”>
<column name=“PkExiCargo” />
<generator class=“native”></generator>
</id>
<timestamp name=“timestamp” column=“Timestamp” />
<many-to-one name="cargo" class="br.com.shc.database.cargo.Cargo" fetch="join">
<column name="FkCargo" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="elemento" class="br.com.shc.database.elemento.Elemento" fetch="join">
<column name="FkElemento" not-null="true">
<comment></comment>
</column>
</many-to-one>
</class>
</hibernate-mapping>
//SELECT GERADO
Hibernate:
select
exicargo0_.PkExiCargo as PkExiCargo1_2_,
exicargo0_.Timestamp as Timestamp1_2_,
exicargo0_.FkCargo as FkCargo1_2_,
exicargo0_.FkElemento as FkElemento1_2_,
cargo1_.PkCargo as PkCargo0_0_,
cargo1_.Timestamp as Timestamp0_0_,
cargo1_.Descricao as Descricao0_0_,
elemento2_.PkElemento as PkElemento2_1_,
elemento2_.Timestamp as Timestamp2_1_,
elemento2_.FkSubord as FkSubord2_1_,
elemento2_.Nome as Nome2_1_,
elemento2_.Codigo as Codigo2_1_,
elemento2_.Sigla as Sigla2_1_,
elemento2_.CNPJ as CNPJ2_1_,
elemento2_.IE as IE2_1_
from
exicargo exicargo0_
inner join
cargo cargo1_
on exicargo0_.FkCargo=cargo1_.PkCargo
inner join
elemento elemento2_
on exicargo0_.FkElemento=elemento2_.PkElemento
where
exicargo0_.PkExiCargo=?