-->
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.  [ 8 posts ] 
Author Message
 Post subject: HHH000386: ResultSet had no statement associated with it
PostPosted: Thu Feb 07, 2013 12:26 am 
Newbie

Joined: Thu Feb 07, 2013 12:01 am
Posts: 2
Hi,

I am getting below warning message:
WARN HHH000386: ResultSet had no statement associated with it, but was not yet registered

For the below code:
Code:

    private final Random r = new Random();

    private void populateData() {
        int userCount = 10 + r.nextInt(10);
        Session session = Util.getHibernateSession();
        Transaction transaction = session.beginTransaction();
        for (int i = 1; i <= userCount; ++i) {
            session.save(getRandomUser());
        }
        transaction.commit();
    }

    private User getRandomUser() {
        User user = new User();
        user.setName(getRandomName(r.nextBoolean()));
        user.setEmail(getEmail(user.getName()));
        user.setPassword(getRandomPassword());
        return user;
    }


Please Note: This warning is coming for version 4.2.0.CR1. However, It was working fine for version 4.1.9.Final.

Can you please let me know why the warning (HHH000386) is coming and how to prevent this?


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Fri Apr 19, 2013 1:30 am 
Newbie

Joined: Fri Apr 19, 2013 1:17 am
Posts: 1
I get the feeling that your code is creating multiple null results sets of which only the first can be released without warning.

Do you see the warning statement multiple times?

The warning statement is produced by call to LOG.unregisteredResultSetWithoutStatement() in org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl;

Code:
   @Override
   public void release(ResultSet resultSet) {
      LOG.tracev( "Releasing result set [{0}]", resultSet );
      Statement statement;
      try {
         statement = resultSet.getStatement();
      }
      catch ( SQLException e ) {
         throw exceptionHelper.convert( e, "unable to access statement from resultset" );
      }
      if ( statement != null ) {
         if ( LOG.isEnabled( Level.WARN ) && !xref.containsKey( statement ) ) {
            LOG.unregisteredStatement();
         }
         Set<ResultSet> resultSets = xref.get( statement );
         if ( resultSets != null ) {
            resultSets.remove( resultSet );
            if ( resultSets.isEmpty() ) {
               xref.remove( statement );
            }
         }
      }
      else {
         boolean removed = unassociatedResultSets.remove( resultSet );
         if ( !removed ) {
            LOG.unregisteredResultSetWithoutStatement();
         }
      }
      close( resultSet );
   }


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Tue Apr 23, 2013 1:40 am 
Newbie

Joined: Tue Apr 23, 2013 1:11 am
Posts: 2
I can see the same warning being logged and it seems to be an issue with the way generated IDs are being handled.

With a (simple) mapping definition:
Code:
    <class name="com.example.Person" table="PERSON" lazy="false">
        <id name="id" type="long">
            <generator class="native"/>
        </id>
        <property name="name" type="string" not-null="true"/>
    </class>


... and code that attempts to saveOrUpdate it (with no id set - expecting a new generated id) the warning is logged every time. Tracing back from the code mentioned by @ryan the code in org.hibernate.id.IdentityGenerator.GetGeneratedKeysDelegate.executeAndExtract(PreparedStatement, SessionImplementor) will obtain a ResultSet that the JdbcCoordinator doesn't know about:
Code:
public Serializable executeAndExtract(PreparedStatement insert, SessionImplementor session) throws SQLException {
    session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
    ResultSet rs = null;
    try {
        rs = insert.getGeneratedKeys();
        return IdentifierGeneratorHelper.getGeneratedIdentity(
                rs,
                persister.getRootTableKeyColumnNames()[0],
                persister.getIdentifierType()
        );
    }
    finally {
        if ( rs != null ) {
            session.getTransactionCoordinator().getJdbcCoordinator().release( rs );
        }
    }
}


In the above, getGeneratedKeys() is going to (always?) give a ResultSet that is not in the JdbcCoordinatorImpl's collections. Which explains why the warning is seen for every insert where an ID is generated.

It seems like a minor bug - perhaps the rs needs to be registered or the logging changed? I'd appreciate it if anyone could confirm. I guess the work around in the mean time is to turn down the log-levels for org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.JdbcCoordinatorImpl?


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Tue Apr 23, 2013 1:55 am 
Newbie

Joined: Tue Apr 23, 2013 1:11 am
Posts: 2
I forgot to mention that this was with 4.2.0.Final ... looking at the latest source in GitHub, there appears to have been a change to the way the ResultSets are released as part of https://hibernate.atlassian.net/browse/HHH-7984 (not relating to this log-warning issue specifically) but it looks like it may resolve it.

4.2.1 scheduled for release soon (tomorrow?).


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Sun May 05, 2013 9:12 am 
Newbie

Joined: Sun May 05, 2013 8:58 am
Posts: 1
Any updates on this issue? I have the same warning with 4.2.1.Final, but only with Postgres, and not with Hsqldb.
I would be grateful for any hints, if someone managed to fix this, or if I can simply ignore this warning.


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Tue Sep 24, 2013 9:32 am 
Newbie

Joined: Wed Jun 20, 2012 4:55 pm
Posts: 7
I also have this problem with 4.2.5.Final. From Googling it seems it might be fixed in 4.3.0 but I cannot confirm that. I don't see a JIRA for it.

Edit: Opened JIRA https://hibernate.atlassian.net/browse/HHH-8544 for this issue. If I get time I'll try to put together a unit test.


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Tue Sep 24, 2013 6:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 18, 2012 5:03 am
Posts: 36
Location: Fort Wayne, Indiana, USA
See the discussion in https://hibernate.atlassian.net/browse/HHH-8210 for a somewhat related description. We keep a map of Statements and their related ResultSets for automated resource cleanup. 3rd party connection pools can wrap Statements with a proxy, so the map lookup fails (no good way to check for Statement equality other than a literal #equals()).

However, the logs definitely signify a legitimate application issue, most of the time. Please attach a simple reproducer to HHH-8544 or a pull request and I'll take a look.


Top
 Profile  
 
 Post subject: Re: HHH000386: ResultSet had no statement associated with it
PostPosted: Wed Sep 25, 2013 10:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 18, 2012 5:03 am
Posts: 36
Location: Fort Wayne, Indiana, USA
As I mentioned in HHH-8544:

What actually happened is that the true issue was corrected in HHH-7984. However, one follow-up commit wasn't backported to 4.2 (whoops): https://github.com/hibernate/hibernate-orm/commit/dc193c32c588d609ab45ff96511d5f9219fed569

I'm cherry-picking and committing that – it'll be out in 4.2.7. Or, you can try it now in 4.3.0.Beta1 or later.


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