java - Hibernate H2 database locks after project rebuild -
i setting spring hibernate h2 application. when server starts works after update (rebuild project in eclipse without restarting tomcat) following error messages saying database file can't accessed.
error messages:
java.lang.illegalstateexception: file locked: nio:/home/bob/datastore.mv.db [1.4.187/7] java.nio.channels.overlappingfilelockexception org.apache.commons.dbcp.sqlnestedexception: cannot create poolableconnectionfactory (database may in use:
after googling error tried adding file_lock=no
, db_close_on_exit=true
url no luck.
context.xml
file
<context:annotation-config /> <context:component-scan base-package="com" /> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource"> <property name="driverclassname" value="org.h2.driver" /> <!-- <property name="url" value="jdbc:h2:tcp://localhost/~/datastore;file_lock=no;db_close_on_exit=true" /> --> <property name="url" value="jdbc:h2:file:~/datastore;file_lock=no;db_close_on_exit=true;mvcc=true" /> <property name="username" value="" /> <property name="password" value="" /> </bean> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="packagestoscan" value="com.entities" /> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.h2dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.enable_lazy_load_no_trans">true</prop> <prop key="format_sql">true</prop> <prop key="use_sql_comments">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.hibernate4.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean>
what can database not locked every time project rebuilt.
also, eclipse rebuilding application after everytime database updated. how can stop this?
try db_close_on_exit=false
, spring docs
if, whatever reason, configure connection url embedded database, care should taken ensure database’s automatic shutdown disabled. if you’re using h2 should use db_close_on_exit=false so.
Comments
Post a Comment