2011-05-06 44 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

相關問題