These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Lazy loading and unique constraints on secondary indexes
PostPosted: Thu Feb 05, 2009 6:53 pm 
Newbie

Joined: Thu Feb 05, 2009 6:46 pm
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

NHibernate 2.0.1

NHibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed

SQLite 3

Hi every body,

I have the following problem.

1) All my collections are lazy
2) I try to add a record with a duplicate fied value "Name", when I try to do this, a NHibernate.Exceptions.GenericADOException is fired
3) When I try to make a second insert (not a duplicate), the previous insert is still pending and regenrates the same execution
3) ISession.Clear() solves the problems but when I try to access my collection, an exception of a type NHibernate.LazyInitializationException

What can I do please ?

Best regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 3:42 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
When you get an exception the session gets invalid. YOu have to close it and open a new one.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 4:48 am 
Newbie

Joined: Thu Feb 05, 2009 6:46 pm
Posts: 4
Hi,

What about the already loaded objects ?

P.S : My SessionFlags IsOpen and IsConnected are still to true but in the log, it tells me that the session has been shut down.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 5:11 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
These objects are ok, but if you want to update, you have to attach them to a new session.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 5:58 am 
Newbie

Joined: Thu Feb 05, 2009 6:46 pm
Posts: 4
Hi,

Instead of using db secondary index, is there a way to apply unique constraints on Hibernate rather than the DB layer ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 6:14 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can have a look at NHibernate.Validator project. But regardless of the way you implement it, it will probably break lazy-loading, meaning hibernate will load the complete collection for checking the constraint. As an alternative you can implement a function somewhere in your repository, that checks the name before you add the new item to the collection (select id from ... where name = :name).

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.