2011-05-06 90 views
1

我正在使用orientdb。样品是很简单的:为什么在关闭连接时抛出异常?

package models; 

import java.util.List; 

import com.orientechnologies.orient.core.db.object.ODatabaseObjectPool; 
import com.orientechnologies.orient.core.db.object.ODatabaseObjectTx; 
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; 

public class User { 

    public String name; 

    public static void main(String[] args) { 
     String uri = "local:c:\\orientdb"; 

     ODatabaseObjectTx db = ODatabaseObjectPool.global().acquire(uri, "admin", "admin"); 
     db.getEntityManager().registerEntityClass(User.class); 

     User user = new User(); 
     user.name = "aaa"; 
     db.save(user); 

     List<?> list = db.query(new OSQLSynchQuery<Long>("select count(*) from User")); 
     System.out.println(list); 
     db.commit(); 
     db.close(); // ****** throws exception 
    } 
} 

但最后一行db.close()将抛出一个异常:

Exception in thread "main" com.orientechnologies.common.concur.lock.OLockException: Can't release a database URL not acquired before. URL: c:\orientdb 
    at com.orientechnologies.orient.core.db.ODatabasePoolAbstract.release(ODatabasePoolAbstract.java:81) 
    at com.orientechnologies.orient.core.db.ODatabasePoolBase.release(ODatabasePoolBase.java:43) 
    at com.orientechnologies.orient.core.db.object.ODatabaseObjectTxPooled.close(ODatabaseObjectTxPooled.java:81) 
    at models.User.main(User.java:26) 

哪里错了?

+0

db.isClosed()在commit()之后返回什么? – MeBigFatGuy 2011-05-06 03:59:51

+0

@MeBigFatGuy,我发现它是一个orientdb的bug。看到我的回答 – Freewind 2011-05-06 06:34:25

+0

当我在java中使用数据库时遇到了同样的情况,并且我得到了异常,因为有可能连接没有建立。所以,如果没有入门,连接就无法关闭,因此是一个例外。我想在使用OrientDB中的windows路径建立连接时会出现错误,因为我发现Freewind的评论。 – 2011-05-06 07:03:33

回答

5

最后,我发现它是Orientdb的一个bug。它无法正确处理Windows路径,并且不提供良好的错误消息。

如果我使用local:c:/orientdb而不是local:c:\orientdb,一切都很好。

我已经向orientdb团队报告了这个。

+0

我试了两次,仍然得到相同的错误。 – KJW 2011-10-31 12:08:07

+0

感谢您的确认!刚刚遇到同样的错误。 – 2012-03-01 23:21:56

相关问题