Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lazy initialization exception

 
Rafael Andrade
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. I'm having an annoying problem. I got a mapped property on my "boleto" class, and it's working well while saving the object in the db:

@ManyToOne (targetEntity = Pessoa.class, fetch = FetchType.LAZY)
@JoinColumn (name = "ID_PESSOA_SACADO", nullable=false)
private Pessoa sacado; ... getters and setters...

when I get the object from the db, it comes without the "sacado", of course, because it's lazy. When I try to load it in the DAO like this:

boleto = (BoletoVO) sess.merge(boleto);
Hibernate.initialize(boleto.getSacado());

it doesn't bring the object "sacado", and when I click on it on the Debug mode, it gives me:

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

the id of the "sacado" property is allright in the db.

when I run this HQL:
select bol.sacado from BoletoVO bol join bol.taxa join bol.sacado where...
it returns the right object. What is happening? thanks!
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try changing you entry to "@ManyToOne( cascade = {CascadeType.MERGE}, targetEntity = Pessoa.class, fetch = FetchType.LAZY)
[ August 01, 2007: Message edited by: Arun Kumarr ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic