-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate fails because InetAddress.getLocalHost() fails
PostPosted: Tue Mar 28, 2017 6:05 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
My application works fine on Windows, OSX and Ubuntu and other flavours of linux, until now. On an arm 32 machine using jdk-8u121-linux-arm32-vfp-hflt.tar.gz it is hanging on buildSessionFactory trying to create a Hibernate database using pure java database H2. I'm using the latest version of hibernate I could use without needing code changes (4.3.11.Final) due to change to SchemaExport after that.

Code:
public static void recreateDatabase()
        {
            Configuration config;
            config =
                    HibernateUtil.getInitializedConfigurationAndRebuildAuditTables();
            new SchemaExport(config).create(false,true);
            factory = config.buildSessionFactory();
        }

With jstack I have found the offending thread
Code:
"C3P0PooledConnectionPoolManager[identityToken->tys5dp9n86d1sl8vqh|f278eb]-HelperThread-#0" #9 daemon prio=5 os_prio=0 tid=0x7a1747b8 nid=0x75d3 runnable [0x79d60000]
           java.lang.Thread.State: RUNNABLE
                at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
                at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
                at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
                at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
                - locked <0x8eddfe38> (a java.lang.Object)
                at org.h2.util.NetUtils.getLocalAddress(NetUtils.java:272)
                - locked <0x7c040f80> (a java.lang.Class for org.h2.util.NetUtils)
                at org.h2.store.FileLock.lockSocket(FileLock.java:380)
                at org.h2.store.FileLock.lock(FileLock.java:138)
                - locked <0x7be62750> (a org.h2.store.FileLock)
                at org.h2.engine.Database.open(Database.java:662)
                - locked <0x7bc23a90> (a org.h2.engine.Database)
                at org.h2.engine.Database.openDatabase(Database.java:276)
                at org.h2.engine.Database.<init>(Database.java:270)
                at org.h2.engine.Engine.openSession(Engine.java:64)
                at org.h2.engine.Engine.openSession(Engine.java:176)
                - locked <0x8ee8bc50> (a org.h2.engine.Engine)
                at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
                at org.h2.engine.Engine.createSession(Engine.java:137)
                at org.h2.engine.Engine.createSession(Engine.java:27)
                at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
                at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
                at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
                at org.h2.Driver.connect(Driver.java:69)
                at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
                at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
                at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
                at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
                at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
                at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
                at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
                at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
                at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)



and I have written this test program to demomstrate that InetAddress.getByName("localhost") works but getLocalHost() fails

Code:
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Addresses
{
     public static void main(String[] args) {

        try {
           InetAddress address= InetAddress.getByName("localhost");
           System.out.println(address.getHostName()+ "-"+address.getHostAddress());

           address= InetAddress.getLocalHost();
           System.out.println(address.getHostName()+ "-"+address.getHostAddress());

        } catch (UnknownHostException e) {
           e.printStackTrace();
        }
     }
}


that gives
Code:
localhost-127.0.0.1
java.net.UnknownHostException: N1: N1: Name or service not known
        at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
        at Addresses.main(Addresses.java:12)
Caused by: java.net.UnknownHostException: N1-ZS10: Name or service not known
        at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
        at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
        ... 1 more



I dont know why InetAddress.getByName("localhost") is failing, but is there a way to configure Hibernate to prevent it making the getLocalHost() call

thanks Paul


Top
 Profile  
 
 Post subject: Re: Hibernate fails because InetAddress.getLocalHost() fails
PostPosted: Tue Mar 28, 2017 8:54 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
If you take a look on the StackTrace, you will see that it's not a Hibernate issue, but an H2 one:

Code:
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
                at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
                at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
                at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
                - locked <0x8eddfe38> (a java.lang.Object)
                at org.h2.util.NetUtils.getLocalAddress(NetUtils.java:272)
                - locked <0x7c040f80> (a java.lang.Class for org.h2.util.NetUtils)
                at org.h2.store.FileLock.lockSocket(FileLock.java:380)
                at org.h2.store.FileLock.lock(FileLock.java:138)
                - locked <0x7be62750> (a org.h2.store.FileLock)
                at org.h2.engine.Database.open(Database.java:662)


The FileLock in H2 calls the NetUtils.getLocalAddress and is causing this issue.

You can switch to a different DB: HSQLDB, Derby or MariaDB, PostgreSQL.


Top
 Profile  
 
 Post subject: Re: Hibernate fails because InetAddress.getLocalHost() fails
PostPosted: Tue Mar 28, 2017 9:08 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
Oh gosh how did i miss that, okay thanks for pointing that out to me Ill contact h2 as I really dont want to move away from h2.


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