-->
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.  [ 9 posts ] 
Author Message
 Post subject: Validating lazily fetched collections - flush() problem
PostPosted: Thu Aug 09, 2007 3:39 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Hi All,

It appears that validating a collection, with something like @Size, that is not initialized causes it to attempt to initialize the collection:

Code:
01:53:55,587 ERROR [http-8080-Processor23] AssertionFailure:22 - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection [com.opterus.opscenter.model.common.Brand.regions] was not processed by flush()
   at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:205)
   at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:333)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:28)


Is there a way to make the validator skip uninitialized collections?

I'm using version 3.0.0.ga of Hibernate Validator and version 3.3.0.ga of Hibernate Annotations common.

Thanks in advance,
Ian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 9:06 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
I notice a year and a half or so back ANN-153 seems to mention not checking uninitialized collections, but I can't seem to find the associated source change...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 9:14 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
ianlong wrote:
I notice a year and a half or so back ANN-153 seems to mention not checking uninitialized collections, but I can't seem to find the associated source change...


It's actually ANN-149.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 10:12 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Actually, it is only collections of composite-elements that causes problems. If I have a collection of entities that are uninitialized the validation works as expected. This collection will cause problems however:


Code:
      <set name="activatedModules"
          lazy="true"
          table="location_module_activation">
          <key column="location_id" />

          <composite-element class="com.opterus.opscenter.model.module.ActivatedModule" >   
             <property name="activationDate" column="activate_date" not-null="true" />
             <many-to-one name="module" class="com.opterus.opscenter.model.module.Module" column="module_id" not-null="true" unique="false" />
          </composite-element>
       </set>   


Anyone have any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 8:30 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Open a new JIRA issue with the details you gave, I'll deal with that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 11:40 am 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
emmanuel wrote:
Open a new JIRA issue with the details you gave, I'll deal with that.


Thanks.

Jira issue HV-37 created: http://opensource.atlassian.com/project ... owse/HV-37

Cheers,
Ian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2007 10:04 am 
Beginner
Beginner

Joined: Mon Sep 12, 2005 3:27 am
Posts: 48
Hi emmanuel,

please see (and fix) ) also bug HHH-2763 - this bug lists also a problem with lazy collections, listener framework and flush !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 12:25 pm 
Newbie

Joined: Tue Feb 21, 2006 12:22 pm
Posts: 16
The problem is that AbstractFlushingEventListener.performExecutions() can result in new CollectionEntrys being created (because listeners access lazy collections, etc...). These CollectionEntry objects are technically created during a flush but not when the PersistenceConext.flushing attribute is set.

I looks safe to update AbstractFlushingEventListener.performExecutions() to:

session.getPersistenceContext().setFlushing(true);
try {
session.getJDBCContext().getConnectionManager().flushBeginning();
// we need to lock the collection caches before
// executing entity inserts/updates in order to
// account for bidi associations
session.getActionQueue().prepareActions();
session.getActionQueue().executeActions();
}
catch (HibernateException he) {
log.error("Could not synchronize database state with session", he);
throw he;
}
finally {
session.getPersistenceContext().setFlushing(false);
session.getJDBCContext().getConnectionManager().flushEnding();
}

That should get rid of this issue, but I am have not analyzed everything that occurs in session.getActionQueue().executeActions() so there could be some side affect, but since the 'flushing' attribute is really only used for CollectionEntry objects, it seems safe.


Top
 Profile  
 
 Post subject: Re: Validating lazily fetched collections - flush() problem
PostPosted: Sun Feb 28, 2010 3:19 am 
Newbie

Joined: Sun Feb 28, 2010 3:14 am
Posts: 1
thanks learn hypnosis


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.