Hello,
i've stumbled with this problem recently, where i have this Entity Evento, and, by doing a simple session.get(Evento.class, id) it returns null, however, by issuing a hql query like "from Evento where id = :id" it does returns the expected entitiy.
Code:
public static void main(String[] args) {
Integer codEvento = 1929830;
Session session = createSession();
System.out.println(session.get(Evento.class, codEvento)); // prints "null"
System.out.println(session.createQuery("from Evento where id = :codEvento").setParameter("codEvento", codEvento).uniqueResult()); //prints the expected event
session.close();
}
Bellow is the generated hibernate output, as well as the prints by System.out:
Quote:
Hibernate: select evento0_.codevento as codevento41_9_, evento0_.situacao as situacao41_9_, evento0_.CodAB as CodAB41_9_, evento0_.CodAE as CodAE41_9_, evento0_.Ano as Ano41_9_, evento0_.IndAvaliarTec as IndAvali7_41_9_, evento0_.codcadevento as codcade32_41_9_, evento0_.carghor as carghor41_9_, evento0_.custoevento as custoeve9_41_9_, evento0_.dataabertura as dataabe10_41_9_, evento0_.datacan as datacan41_9_, evento0_.datafimevento as datafim12_41_9_, evento0_.duraula as duraula41_9_, evento0_.IndExportar as IndExpo14_41_9_, evento0_.percfreqmin as percfre15_41_9_, evento0_.qtdlimdiareserv as qtdlimd16_41_9_, evento0_.motivocan as motivocan41_9_, evento0_.CodMunicipio as CodMuni33_41_9_, evento0_.CodObj as CodObj41_9_, evento0_.observacao as observacao41_9_, evento0_.codprod as codprod41_9_, evento0_.codautorel as codautorel41_9_, evento0_.qtdinscritos as qtdinsc20_41_9_, evento0_.qtdmaxpart as qtdmaxpart41_9_, evento0_.qtdminpagantes as qtdminp22_41_9_, evento0_.qtdreservas as qtdrese23_41_9_, evento0_.codreserva as codreserva41_9_, evento0_.CodSebrae as CodSebrae41_9_, evento0_.CodSol as CodSol41_9_, evento0_.TituloEvento as TituloE26_41_9_, evento0_.indfechado as indfechado41_9_, evento0_.codunidop as codunidop41_9_, evento0_.usuariocan as usuariocan41_9_, evento0_.UsuarioConsol as Usuario29_41_9_, evento0_.UsuarioResp as Usuario30_41_9_, evento0_.valorevento as valorev31_41_9_, cadevento1_.codcadevento as codcadev1_47_0_, cadevento1_.codareaevento as codareae2_47_0_, cadevento1_.chprevista as chprevista47_0_, cadevento1_.desccadevento as desccade4_47_0_, cadevento1_.qtdlimdiareserv as qtdlimdi5_47_0_, cadevento1_.IndExportar as IndExpor6_47_0_, cadevento1_.indevefechado as indevefe7_47_0_, cadevento1_.CodFichaAval as CodFicha8_47_0_, cadevento1_.percfreqmin as percfreq9_47_0_, cadevento1_.qtdinscmaxprev as qtdinsc10_47_0_, cadevento1_.qtdminpagantes as qtdminp11_47_0_, cadevento1_.observacao as observacao47_0_, cadevento1_.codautorel as codautorel47_0_, cadevento1_.CodSebrae as CodSebrae47_0_, cadevento1_.codtipoevento as codtipo17_47_0_, cadevento1_.indfechado as indfechado47_0_, cadevento1_.valorevento as valorev14_47_0_, eventotipo2_.codtipoevento as codtipoe1_43_1_, eventotipo2_.Situacao as Situacao43_1_, eventotipo2_.DescTipoEven as DescTipo3_43_1_, horarios3_.CodEvento as CodEvento41_11_, horarios3_.DataInicio as DataInicio11_, horarios3_.CodEvento as CodEvento11_, horarios3_.HoraInicial as HoraInic3_11_, horarios3_.DataInicio as DataInicio37_2_, horarios3_.CodEvento as CodEvento37_2_, horarios3_.HoraInicial as HoraInic3_37_2_, horarios3_.DataFinal as DataFinal37_2_, horarios3_.HoraFinal as HoraFinal37_2_, horarios3_.CodReserva as CodReserva37_2_, horarios3_.IndPrincipal as IndPrinc6_37_2_, eventorese4_.codreserva as codreserva44_3_, eventorese4_.bloquear as bloquear44_3_, eventorese4_.datafimres as datafimres44_3_, eventorese4_.datainires as datainires44_3_, eventorese4_.datareserva as datarese5_44_3_, eventorese4_.finalidres as finalidres44_3_, eventorese4_.horafimres as horafimres44_3_, eventorese4_.horainires as horainires44_3_, eventorese4_.codlocal as codlocal44_3_, eventorese4_.pessoares as pessoares44_3_, eventoloca5_.codlocal as codlocal38_4_, eventoloca5_.Situacao as Situacao38_4_, eventoloca5_.codbairro as codbairro38_4_, eventoloca5_.capacidade as capacidade38_4_, eventoloca5_.cep as cep38_4_, eventoloca5_.codcid as codcid38_4_, eventoloca5_.pescontato as pescontato38_4_, eventoloca5_.telcontato as telcontato38_4_, eventoloca5_.desclocal as desclocal38_4_, eventoloca5_.endereco as endereco38_4_, eventoloca5_.complemento as compleme8_38_4_, eventoloca5_.codest as codest38_4_, eventoloca5_.codlogr as codlogr38_4_, eventoloca5_.numero as numero38_4_, eventoloca5_.codpais as codpais38_4_, eventoloca5_.CodSebrae as CodSebrae38_4_, eventoloca5_.TipoLocal as TipoLocal38_4_, bairro6_.codbairro as codbairro48_5_, bairro6_.abrevbairro as abrevbai2_48_5_, bairro6_.codcid as codcid48_5_, bairro6_.indcadcorreio as indcadco3_48_5_, bairro6_.descbairro as descbairro48_5_, bairro6_.indtipo as indtipo48_5_, cidade7_.CodCid as CodCid49_6_, cidade7_.AnoRefPop as AnoRefPop49_6_, cidade7_.AnoRefTot as AnoRefTot49_6_, cidade7_.IndAtualizacao as IndAtual4_49_6_, cidade7_.IndAtuCid as IndAtuCid49_6_, cidade7_.IndCapital as IndCapital49_6_, cidade7_.Capital as Capital49_6_, cidade7_.CodEst as CodEst49_6_, cidade7_.Fonte as Fonte49_6_, cidade7_.CodMicro as CodMicro49_6_, cidade7_.DescCid as DescCid49_6_, cidade7_.NumEmp as NumEmp49_6_, cidade7_.NumEmpCom as NumEmpCom49_6_, cidade7_.NumEmpSer as NumEmpSer49_6_, cidade7_.NumEscolas as NumEscolas49_6_, cidade7_.NumFaculd as NumFaculd49_6_, cidade7_.NumIndust as NumIndust49_6_, cidade7_.PopCid as PopCid49_6_, cidade7_.PopRur as PopRur49_6_, cidade7_.PopUrb as PopUrb49_6_, estado8_.CodEst as CodEst53_7_, estado8_.AbrevEst as AbrevEst53_7_, estado8_.AreaOcup as AreaOcup53_7_, estado8_.IndAtualizacao as IndAtual4_53_7_, estado8_.DataAtualiz as DataAtua5_53_7_, estado8_.Fonte as Fonte53_7_, estado8_.DescEst as DescEst53_7_, estado8_.CodPais as CodPais53_7_, estado8_.Populacao as Populacao53_7_, logradouro9_.codlogr as codlogr51_8_, logradouro9_.desclogr as desclogr51_8_, logradouro9_.desclograbrev as desclogr3_51_8_ from Evento evento0_ inner join CadEvento cadevento1_ on evento0_.codcadevento=cadevento1_.codcadevento left outer join TipoEvento eventotipo2_ on cadevento1_.codtipoevento=eventotipo2_.codtipoevento left outer join HorarioEvento horarios3_ on evento0_.codevento=horarios3_.CodEvento left outer join reservalocal eventorese4_ on horarios3_.CodReserva=eventorese4_.codreserva left outer join localevento eventoloca5_ on eventorese4_.codlocal=eventoloca5_.codlocal left outer join bairro bairro6_ on eventoloca5_.codbairro=bairro6_.codbairro left outer join cidade cidade7_ on bairro6_.codcid=cidade7_.CodCid left outer join Estado estado8_ on cidade7_.CodEst=estado8_.CodEst left outer join logradouro logradouro9_ on eventoloca5_.codlogr=logradouro9_.codlogr where evento0_.codevento=? order by horarios3_.DataInicio asc, horarios3_.HoraInicial asc
null
Hibernate: select evento0_.codevento as codevento41_, evento0_.situacao as situacao41_, evento0_.CodAB as CodAB41_, evento0_.CodAE as CodAE41_, evento0_.Ano as Ano41_, evento0_.IndAvaliarTec as IndAvali7_41_, evento0_.codcadevento as codcade32_41_, evento0_.carghor as carghor41_, evento0_.custoevento as custoeve9_41_, evento0_.dataabertura as dataabe10_41_, evento0_.datacan as datacan41_, evento0_.datafimevento as datafim12_41_, evento0_.duraula as duraula41_, evento0_.IndExportar as IndExpo14_41_, evento0_.percfreqmin as percfre15_41_, evento0_.qtdlimdiareserv as qtdlimd16_41_, evento0_.motivocan as motivocan41_, evento0_.CodMunicipio as CodMuni33_41_, evento0_.CodObj as CodObj41_, evento0_.observacao as observacao41_, evento0_.codprod as codprod41_, evento0_.codautorel as codautorel41_, evento0_.qtdinscritos as qtdinsc20_41_, evento0_.qtdmaxpart as qtdmaxpart41_, evento0_.qtdminpagantes as qtdminp22_41_, evento0_.qtdreservas as qtdrese23_41_, evento0_.codreserva as codreserva41_, evento0_.CodSebrae as CodSebrae41_, evento0_.CodSol as CodSol41_, evento0_.TituloEvento as TituloE26_41_, evento0_.indfechado as indfechado41_, evento0_.codunidop as codunidop41_, evento0_.usuariocan as usuariocan41_, evento0_.UsuarioConsol as Usuario29_41_, evento0_.UsuarioResp as Usuario30_41_, evento0_.valorevento as valorev31_41_ from Evento evento0_ where evento0_.codevento=?
Hibernate: select horarios0_.CodEvento as CodEvento41_7_, horarios0_.DataInicio as DataInicio7_, horarios0_.CodEvento as CodEvento7_, horarios0_.HoraInicial as HoraInic3_7_, horarios0_.DataInicio as DataInicio37_6_, horarios0_.CodEvento as CodEvento37_6_, horarios0_.HoraInicial as HoraInic3_37_6_, horarios0_.DataFinal as DataFinal37_6_, horarios0_.HoraFinal as HoraFinal37_6_, horarios0_.CodReserva as CodReserva37_6_, horarios0_.IndPrincipal as IndPrinc6_37_6_, eventorese1_.codreserva as codreserva44_0_, eventorese1_.bloquear as bloquear44_0_, eventorese1_.datafimres as datafimres44_0_, eventorese1_.datainires as datainires44_0_, eventorese1_.datareserva as datarese5_44_0_, eventorese1_.finalidres as finalidres44_0_, eventorese1_.horafimres as horafimres44_0_, eventorese1_.horainires as horainires44_0_, eventorese1_.codlocal as codlocal44_0_, eventorese1_.pessoares as pessoares44_0_, eventoloca2_.codlocal as codlocal38_1_, eventoloca2_.Situacao as Situacao38_1_, eventoloca2_.codbairro as codbairro38_1_, eventoloca2_.capacidade as capacidade38_1_, eventoloca2_.cep as cep38_1_, eventoloca2_.codcid as codcid38_1_, eventoloca2_.pescontato as pescontato38_1_, eventoloca2_.telcontato as telcontato38_1_, eventoloca2_.desclocal as desclocal38_1_, eventoloca2_.endereco as endereco38_1_, eventoloca2_.complemento as compleme8_38_1_, eventoloca2_.codest as codest38_1_, eventoloca2_.codlogr as codlogr38_1_, eventoloca2_.numero as numero38_1_, eventoloca2_.codpais as codpais38_1_, eventoloca2_.CodSebrae as CodSebrae38_1_, eventoloca2_.TipoLocal as TipoLocal38_1_, bairro3_.codbairro as codbairro48_2_, bairro3_.abrevbairro as abrevbai2_48_2_, bairro3_.codcid as codcid48_2_, bairro3_.indcadcorreio as indcadco3_48_2_, bairro3_.descbairro as descbairro48_2_, bairro3_.indtipo as indtipo48_2_, cidade4_.CodCid as CodCid49_3_, cidade4_.AnoRefPop as AnoRefPop49_3_, cidade4_.AnoRefTot as AnoRefTot49_3_, cidade4_.IndAtualizacao as IndAtual4_49_3_, cidade4_.IndAtuCid as IndAtuCid49_3_, cidade4_.IndCapital as IndCapital49_3_, cidade4_.Capital as Capital49_3_, cidade4_.CodEst as CodEst49_3_, cidade4_.Fonte as Fonte49_3_, cidade4_.CodMicro as CodMicro49_3_, cidade4_.DescCid as DescCid49_3_, cidade4_.NumEmp as NumEmp49_3_, cidade4_.NumEmpCom as NumEmpCom49_3_, cidade4_.NumEmpSer as NumEmpSer49_3_, cidade4_.NumEscolas as NumEscolas49_3_, cidade4_.NumFaculd as NumFaculd49_3_, cidade4_.NumIndust as NumIndust49_3_, cidade4_.PopCid as PopCid49_3_, cidade4_.PopRur as PopRur49_3_, cidade4_.PopUrb as PopUrb49_3_, estado5_.CodEst as CodEst53_4_, estado5_.AbrevEst as AbrevEst53_4_, estado5_.AreaOcup as AreaOcup53_4_, estado5_.IndAtualizacao as IndAtual4_53_4_, estado5_.DataAtualiz as DataAtua5_53_4_, estado5_.Fonte as Fonte53_4_, estado5_.DescEst as DescEst53_4_, estado5_.CodPais as CodPais53_4_, estado5_.Populacao as Populacao53_4_, logradouro6_.codlogr as codlogr51_5_, logradouro6_.desclogr as desclogr51_5_, logradouro6_.desclograbrev as desclogr3_51_5_ from HorarioEvento horarios0_ inner join reservalocal eventorese1_ on horarios0_.CodReserva=eventorese1_.codreserva left outer join localevento eventoloca2_ on eventorese1_.codlocal=eventoloca2_.codlocal left outer join bairro bairro3_ on eventoloca2_.codbairro=bairro3_.codbairro left outer join cidade cidade4_ on bairro3_.codcid=cidade4_.CodCid left outer join Estado estado5_ on cidade4_.CodEst=estado5_.CodEst left outer join logradouro logradouro6_ on eventoloca2_.codlogr=logradouro6_.codlogr where horarios0_.CodEvento=? order by horarios0_.DataInicio asc, horarios0_.HoraInicial asc
F.E Formação de Preço de Venda
As you can see, its a big entity, with lots of relationships. I can post the classes if needed.
I did some search in the forum / the internet, but didnt find nothing ressembling this subject. Hope u guys can help me.I
by the way, its HIBERNATE 3.6.1 Final (can post my maven pom.xml if necessary)
p.s.: sorry for my english.