2014-03-30 3 views
0

3 부분으로 구성된 앱을 개발 중입니다. - JavaFX Desktop app. - Java Server WebApp - AndroidApp동시 액세스 SQLite Da

SQLite 데이터베이스를 매핑하는 데 Hibernate를 사용하고 있습니다.

그러나 데스크톱 응용 프로그램은 열려 있고 그것이 나에게 오류 제공 서버 통해 서 AndroidApp에서 새 ibject를 삽입하려고하면 java.sql.SQLException: database is locked

내있는 hibernate.cfg.xml 파일 :

<property name="show_sql">true</property> 
<property name="format_sql">true</property> 
    <property name="dialect">dialect.SQLiteDialect</property> 
    <property name="connection.driver_class">org.sqlite.JDBC</property> 
    <property name="connection.url">jdbc:sqlite:grainsa_provisional.sqlite</property> 
    <property name="connection.username"></property> 
    <property name="connection.password"></property> 

을 그리고 서버 및 데스크톱의 경우와 같은 방식으로 내 "개체 관리자"가됩니다.

private Session mSession; 
private Transaction mTransaction; 

private void initQuery() throws HibernateException { 
    mSession = HibernateUtil.getSessionFactory().openSession(); 
    mTransaction = mSession.beginTransaction(); 
} 

private void manejaExcepcion(HibernateException hibernateException) { 
    mTransaction.rollback(); 
    throw new HibernateException("ha ocurrido un error con la Base de Datos!!!", hibernateException); 
} 


public Conductor selectConductorByID(Integer id) { 
    Conductor conductor = new Conductor(); 
    try{ 
     initQuery(); 
     conductor = (Conductor) mSession.get(Conductor.class, id); 
    } catch (HibernateException e){ 
     manejaExcepcion(e); 
     throw e; 
    } finally { 
     mSession.close(); 
    } 
    return conductor; 
} 

자세한 정보가 필요하면 문의하십시오.

내가 뭘 잘못하고있어?

감사합니다 모두와 내 영어에 대해 미안 해요!

편집 : mi 데스크톱 JavaFX 응용 프로그램의 액세스 모드를 변경하여 서버를 통해 쿼리를 만들지 만 생각하면 시간이 많이 걸릴 것이므로 최선의 방법이라고 생각하지 않습니다.

편집 2 : 이것은 열어서 쿼리를 만들고 데이터 바사의 잠김/쿼리/잠금 해제에 대한 적절한 결론입니다.

private void initQuery() throws HibernateException { 
    mSession = HibernateUtil.getSessionFactory().openSession(); 
    mTransaction = mSession.beginTransaction(); 
} 

private void manejaExcepcion(HibernateException hibernateException) { 
    mTransaction.rollback(); 
    throw new HibernateException("ha ocurrido un error con la Base de Datos!!!", hibernateException); 
} 


public Conductor selectConductorByID(Integer id) { 
    Conductor conductor = new Conductor(); 
    try{ 
     initQuery(); 
     conductor = (Conductor) mSession.get(Conductor.class, id); 
    } catch (HibernateException e){ 
     manejaExcepcion(e); 
     throw e; 
    } finally { 
     mSession.close(); 
    } 
    return conductor; 
} 

도와주세요! 고마워! 자주 묻는 질문에서 조금 deseperated 미안 ...

+0

내가 볼 수 없기 때문에이 어떤 식 으로든 도움이된다면 내가 모르는 곳 쿼리있는 방법 최대 절전 문서를 볼 수있는 코드를 변경해야 잠금 당신은 그것들을 호출하고있다. 그러나 나는 [이 포스트] (http://stackoverflow.com/a/5659027/1300817)를 보았고'sqlite3_finalize (compiledStatement);와'sqlite3_close (database);를 호출하여 파이널 컴파일 된 진술과 데이터베이스를 닫습니다 –

답변

0

(5) SQLite는 질문에 :

But use caution: this locking mechanism might not work correctly if the database file is kept on an NFS filesystem. This is because fcntl() file locking is broken on many NFS implementations. You should avoid putting SQLite database files on NFS if multiple processes might try to access the file at the same time. On Windows, Microsoft's documentation says that locking may not work under FAT filesystems if you are not running the Share.exe daemon. People who have a lot of experience with Windows tell me that file locking of network files is very buggy and is not dependable. If what they say is true, sharing an SQLite database between two or more Windows machines might cause unexpected problems.

어쩌면 이것은 당신을 문제의 원인은? 창문에서 일하고 있습니까?

Multiple processes can have the same database open at the same time. Multiple processes can be doing a SELECT at the same time. But only one process can be making changes to the database at any moment in time, however.

SQLLite는 다중 사용자 시나리오에서는 문제가 있지만 업데이트가 짧고 빠르면 제대로 작동 할 수 있습니다.
코드에서 트랜잭션을 올바르게 닫지 않은 것처럼 보입니다. 어쩌면이 경우는 DB는

당신은 here

private Transaction initQuery() throws HibernateException { 
    mSession = HibernateUtil.getSessionFactory().openSession(); 
    mTransaction = mSession.beginTransaction(); 
    return mTransaction;  
} 


public Conductor selectConductorByID(Integer id) { 
    Conductor conductor = new Conductor(); 
    Transaction tx = null; 
    try{ 
     tx = initQuery(); 
     conductor = (Conductor) mSession.get(Conductor.class, id); 
     //flush and commit before close 
     mSession.flush(); 
     tx.commit(); 
    } catch (HibernateException e){ 
     manejaExcepcion(e); 
     throw e; 
    } finally { 
     mSession.close(); 
    } 
    return conductor; 
} 
+0

고마워, 내가 그것을 시도하고 내가 말할께! – vlopezla

+0

저는 여행 중이며 이번 주말에 해결책을 찾으려고합니다 – vlopezla

+0

문제 없습니다, 업데이트 해 주셔서 감사합니다 :-) –