-->
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.  [ 4 posts ] 
Author Message
 Post subject: Wildfly Clustering and hibernate
PostPosted: Wed Aug 17, 2016 4:23 am 
Newbie

Joined: Wed Aug 17, 2016 4:15 am
Posts: 2
I'm setting up a cluster of wildfly instances to run my application. It's using hibernate for its persistance.

I'm working from the infinispan config from standalone-ha.xml, jgroups I've altered to use tcp ping instead as I cannot use multicast in my environment.

Session replication is working perfectly, my mod_jk load balancer is not using sticky sessions and both of the servers in the cluster (only testing with 2) are serving up pages successfully.

I am experiencing an intermittent issue with hibernate however:
Code:
2016-08-16 10:14:47,518 INFO  [stdout] (default task-8) Caused by: java.lang.NullPointerException: null

2016-08-16 10:14:47,518 INFO  [stdout] (default task-8)     at org.hibernate.collection.internal.AbstractPersistentCollection.openTemporarySessionForLoading(AbstractPersistentCollection.java:274)

2016-08-16 10:14:47,518 INFO  [stdout] (default task-8)     at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:201)

2016-08-16 10:14:47,519 INFO  [stdout] (default task-8)     at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:546)

2016-08-16 10:14:47,519 INFO  [stdout] (default task-8)     at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:133)

2016-08-16 10:14:47,519 INFO  [stdout] (default task-8)     at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:277)

I'm using wildfly 10, which is running hibernate 5.

Source of the class in question: http://grepcode.com/file/repo1.maven.or ... ding%28%29

The class is used for lazy loaded lists (with a one to many relationship), among other things.

Here's some of the code:
Code:
@Table(name = "[User]")
@Entity
public class User extends CommonDomainBase
{

    @OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy = "user", fetch = FetchType.LAZY)
    private List<UserSearchingPreference> searchingPreferences;

    public List<UserSearchingPreference> getSearchingPreferences()
    {
        return searchingPreferences;
    }
}

From what I can see, the sessionFactoryUuid will be serialised when. So if the User is loaded on server 1, replicated to server 2, and a different request which hits server 2 attempts to call getSearchingPreferences() the sessionFactoryUuid which relates to the hibernate session on server 1 cannot be used to lookup the session on server 2, because it won't exist.

Is anyone able to confirm if I'm correct in my assumption and suggest a solution?

I'm not sure whether this is some hibernate configuration that needs adjusting, or if I should be in some way detaching objects before they are replicated.


Top
 Profile  
 
 Post subject: Re: Wildfly Clustering and hibernate
PostPosted: Mon Aug 29, 2016 10:31 am 
Red Hat Associate
Red Hat Associate

Joined: Wed Apr 18, 2012 9:06 pm
Posts: 6
Great find! IMO, the fix should likely be in org.hibernate.collection.internal.AbstractPersistentCollection should also use session.getFactory().getName() for clustering, as session factory name is typically used in clustered environments instead of the UUID:

Code:
   private String sessionFactoryUuid;
   private String sessionFactoryName;

   protected void prepareForPossibleLoadingOutsideTransaction() {
      if ( session != null ) {
         allowLoadOutsideTransaction = session.getFactory().getSessionFactoryOptions().isInitializeLazyStateOutsideTransactionsEnabled();

         if ( allowLoadOutsideTransaction && sessionFactoryName == null ) {
            sessionFactoryName = session.getFactory().getName();
         else if ( allowLoadOutsideTransaction && sessionFactoryUuid == null ) {
            sessionFactoryUuid = session.getFactory().getUuid();
         }
      }
   }

   private SharedSessionContractImplementor openTemporarySessionForLoading() {
      if ( sessionFactoryUuid == null && sessionFactoryName == null ) {
         throwLazyInitializationException( "SessionFactory UUID or name is not known to create temporary Session for loading" );
      }

      final SessionFactoryImplementor sf = (SessionFactoryImplementor)
                                sessionFactoryName != null ? SessionFactoryRegistry.INSTANCE.getNamedSessionFactory(sessionFactoryName) :
            SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid );
      final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession();
      session.getPersistenceContext().setDefaultReadOnly( true );
      session.setFlushMode( FlushMode.MANUAL );
      return session;
   }


Please create a HHH jira for the above change, I think the title should be something like "AbstractPersistentCollection lazy handling in a cluster" and reference this forum post, as well as have your description of the symptoms.

Scott


Top
 Profile  
 
 Post subject: Re: Wildfly Clustering and hibernate
PostPosted: Mon Sep 05, 2016 9:15 pm 
Red Hat Associate
Red Hat Associate

Joined: Wed Apr 18, 2012 9:06 pm
Posts: 6
The link for creating a HHH jira to track this issue is https://hibernate.atlassian.net/browse/HHH. I prefer to let you create the jira, so you get credit for reporting the issue. Please post a link here to the HHH jira that you create, so others can follow it.


Top
 Profile  
 
 Post subject: Re: Wildfly Clustering and hibernate
PostPosted: Wed Sep 07, 2016 8:06 am 
Newbie

Joined: Wed Aug 17, 2016 4:15 am
Posts: 2
Thanks for the reply. I've create a new issue: https://hibernate.atlassian.net/browse/HHH-11091


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.