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