等待Hibernate错误的时间太长

时间:2017-07-22 14:31:04

标签: java mongodb hibernate-ogm

为什么输出流会立即收到错误,而try-catch中的异常会在很长一段时间后(甚至几分钟后)到达?

我正在使用与Mongo数据库连接的Hibernate OGM。 谁能告诉我这是什么问题?如何解决它或我应该学习什么来理解它?

特别是在登录期间:当我尝试使用错误的参数访问数据库时。这里的流警告我发生了com.mongodb.MongoCommandException。虽然应用程序控制仅在com.mongodb.MongoTimeoutException之后返回给我。

下面是System.out

INFORMAZIONI: Exception in monitor thread while connecting to server <hidden>:27017
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='daniele_cuomo', source='admin', password=<hidden>, mechanismProperties={}}
    at com.mongodb.connection.SaslAuthenticator.wrapInMongoSecurityException(SaslAuthenticator.java:157)
    at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:37)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:66)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:44)
    at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:162)
    at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:44)
    at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32)
    at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:109)
    at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:46)
    at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:116)
    at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server <hidden>:27017. The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }
    at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170)
    at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123)
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32)
    at com.mongodb.connection.SaslAuthenticator.sendSaslContinue(SaslAuthenticator.java:121)
    at com.mongodb.connection.SaslAuthenticator.access$100(SaslAuthenticator.java:37)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:63)

2 个答案:

答案 0 :(得分:0)

com.mongodb.MongoTimeoutException转到此类并更改超时期限(如果它可用作开源库)。还看看这里使用的java api是什么。当然,这取决于这里使用的jdk api。

答案 1 :(得分:0)

您可以使用以下属性为mongodb客户端设置属性:

 ContentValues values=new ContentValues();
 values.put("counter",1)
 int rowCount=db.update("stats",values,"act_name=?",new String[]{mAction}); 

您可以使用MongoClientOption.Builder class中的任何属性替换*,例如:

hibernate.ogm.mongodb.driver.*

official Hibernate OGM documentation contains所有细节