-->
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: Exception with MassIndexer: proxy with two open Sessions
PostPosted: Mon Mar 25, 2013 11:22 am 
Newbie

Joined: Fri Apr 20, 2012 11:40 am
Posts: 4
Hi all,

I'm facing a strange issue and I hope some of you may help me.
When I try to use MassIndexer, I've got the following exception:
Code:
15:49:23,653 ERROR [org.hibernate.search.exception.impl.LogErrorHandler] (Hibernate Search: collectionsloader-1) HSEARCH000058: HSEARCH000116: Unexpected error during MassIndexer operation: org.hibernate.HibernateException: illegally attempted to associate a proxy with two open Sessions
   at org.hibernate.proxy.AbstractLazyInitializer.setSession(AbstractLazyInitializer.java:112) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.engine.internal.StatefulPersistenceContext.reassociateProxy(StatefulPersistenceContext.java:606) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.engine.internal.StatefulPersistenceContext.reassociateIfUninitializedProxy(StatefulPersistenceContext.java:565) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.ProxyVisitor.processEntity(ProxyVisitor.java:49) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:124) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:82) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:76) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.AbstractVisitor.process(AbstractVisitor.java:143) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.AbstractReassociateEventListener.reassociate(AbstractReassociateEventListener.java:98) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.event.internal.DefaultLockEventListener.onLock(DefaultLockEventListener.java:81) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:724) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:717) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.internal.SessionImpl.access$1700(SessionImpl.java:170) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.internal.SessionImpl$LockRequestImpl.lock(SessionImpl.java:2276) [hibernate-core-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.indexAllQueue(EntityConsumerLuceneWorkProducer.java:131) [hibernate-search-orm-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.run(EntityConsumerLuceneWorkProducer.java:102) [hibernate-search-orm-4.1.0.Final.jar:4.1.0.Final]
   at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:112) [hibernate-search-orm-4.1.0.Final.jar:4.1.0.Final]
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_01]
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_01]
   at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_01]


This issue occurs even when I use @Indexed on only one entity! This entity has many fields but only one field annotated with @Field :
Code:
@Entity
@Table(name = "DIR_UNITE_FONCTIONNELLE_UFC")
@DiscriminatorValue("UFC")
@ForeignKey(name = "FK_UFC_STR")
@Indexed
public class UniteFonctionnelle extends Structure implements Serializable {

        @Column(name = "UFC_ID_LOCAL", nullable = false)
   @NotBlank(message="{uf.required.local_id}")
   @Field(store=Store.YES, analyze=Analyze.NO)
   private String idLocal;

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "UFC_ENTITE_JURIDIQUE", referencedColumnName = "STR_ID", nullable = false)
   @ForeignKey(name = "FK_UFC_EJR")
   private EntiteJuridique entiteJuridique;

        ... and more fields ...


My classes have the following hierarchy:
UniteFonctionnelle -- inherit from --> Structure
EntiteJuridique -- inherit from --> Structure

Structure, UniteFonctionnelle and EntiteJuridique are stored in differents tables. EntiteJuridique does not have (currently) the @Indexed annotation (nor Structure). Structure class own the @Id field.

Note: this issue appears even if I set luceneWorkerBuildingThreadNum to 1 and luceneWorkerBuildingThreadNum = 1.

I looked into the code (hibernate-search 4.1.0 final and hibernate-core 4.1.0 final) and here is my analysis:
- in BatchIndexingWorkspace.run method, 1 instance of EntityConsumerLuceneWorkProducer, 1 instance of IdentifierConsumerEntityProducer and 1 instance of IdentifierProducer are created (according to luceneWorkerBuildingThreadNum and luceneWorkerBuildingThreadNum).
- first IdentifierProducer is run and requests the DB to retrieve IDs
- then IdendifierConsumerEntityProducer is run and hits the DB to retrieve entities but as the field entiteJuridique is LAZY then hibernate creates a proxy (and this proxy is associated with the current session)
- at last EntityConsumerLuceneWorkProducer is run (consumes entities produced by IdendifierConsumerEntityProducer). First I don't know why but this producer tries to load the field entiteJuridique even if this attribut is not part of the document! As it wants to load the proxy it tries to associate a session to the proxy (which has already one session) => Exception

These producers / consumers are wrapped by an OptionallyWrapInJTATransaction, which creates a new session when there's no JTA transaction (my case). So each producer/consumer has a different session.
[edit] I made a mistake OptionallyWrapInJTATransaction does not create a new session when there's no JTA transaction: it calls run with null parameter. But as there's no upper session, the wrapped instance use
Code:
sessionFactory.openSession()
to get a new session.

I think that this use case is quite common, so may be I have something wrong with my configuration?

Any help would be very, very appreciate.
Thank you so much.
Eric


Top
 Profile  
 
 Post subject: Re: Exception with MassIndexer: proxy with two open Sessions
PostPosted: Tue Mar 26, 2013 7:11 am 
Newbie

Joined: Fri Apr 20, 2012 11:40 am
Posts: 4
I did some tests and get new informations:

UniteFonctionnelle and EntiteJuridique, both inherit from Structure. Structure instances may have an address and may also have a "structureParent" (which is a Structure). And UniteFonctionnelle has an field "entiteJuridique" (which is an EntiteJuridique instance).

Each time I've got an exception I also have the following log :
Code:
Narrowing proxy EntiteJuridique

In my databases most of UniteFonctionnelle instances uses the same EntiteJuridique instance for "structureParent" and "entiteJuridique"

If I set "structureParent" as EAGER then everything works fine.


Top
 Profile  
 
 Post subject: Re: Exception with MassIndexer: proxy with two open Sessions
PostPosted: Wed Mar 27, 2013 8:20 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
There where some issues in Hibernate Search 4.1 because of differences in how Hibernate ORM associated proxies to a new Session (Hibernate Search uses a pipeline with multiple Sessions).

As far as I know they where all fixed, so I would suggest you to upgrade Hibernate Search to 4.2 : it should be a very easy upgrade:

https://github.com/hibernate/hibernate-search/blob/master/changelog.txt

https://community.jboss.org/wiki/HibernateSearchMigrationGuide#Hibernate_Search_420Final

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Exception with MassIndexer: proxy with two open Sessions
PostPosted: Wed Mar 27, 2013 9:09 pm 
Newbie

Joined: Fri Apr 20, 2012 11:40 am
Posts: 4
Hi Sanne,

Thanks for your suggestion. I'll give a try to version 4.2 and let you know if it fixed this issue.

Thanks again
Eric


Top
 Profile  
 
 Post subject: Re: Exception with MassIndexer: proxy with two open Sessions
PostPosted: Wed Apr 03, 2013 6:00 am 
Newbie

Joined: Fri Apr 20, 2012 11:40 am
Posts: 4
Thanks for your answer. In Hibernate Search 4.2, this issue has been resolved so everything works fine now !


Top
 Profile  
 
 Post subject: Re: Exception with MassIndexer: proxy with two open Sessions
PostPosted: Wed Apr 03, 2013 6:47 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Eric, thanks for letting me know!
good feeling :-)

_________________
Sanne
http://in.relation.to/


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.