spa
spa

Reputation: 339

H2 database console error

HI I am first time user of in-memory DB H2. I connected from application using below configuration .I ran application and i am seeing changes in log.

But when i tried to see changes in H2Console and tried to connect it will say as below.It's not able to connect.But when i terminated java application and tried to connect it will connect without errors but i can't see changes done (new rows inserted during application run)

How to see changes in H2 console when application is still running?

enter image description here

hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property> 
        <property name="hibernate.show_sql">true</property>   
        <property name="hibernate.connection.driver">org.h2.Driver</property>   
        <property name="hibernate.connection.user">sa</property>   
        <property name="hibernate.connection.password"></property>   
        <property name="hibernate.connection.url">jdbc:h2:~/h2schema/test</property>   
        <property name="hibernate.hbm2ddl.auto">update</property>   
    </session-factory>
</hibernate-configuration>

App.java

 {
   System.out.println( "Hello World!" );
   Alien alien = new Alien("mk", "white", 26l);
   Alien alien2 = new Alien("mk1", "white1", 26l);
   Configuration configuration = new Configuration().configure().addAnnotatedClass(
         Alien.class);
   SessionFactory factory = configuration.buildSessionFactory();
   Session session = factory.openSession();
   Transaction transaction =  session.getTransaction();
   transaction.begin();
   session.save(alien);
   session.save(alien2);
   System.out.println("-----------");
   System.out.println("created user is "+alien);
   System.out.println("created user is "+alien2);
   System.out.println("-----------");
   transaction.commit();
   session.close();
}

Upvotes: 0

Views: 348

Answers (1)

RattyLaa
RattyLaa

Reputation: 323

As mentioned in here:

H2 database error: Database may be already in use: "Locked by another process"

H2 is locked, try running in server mode with TCP

jdbc:h2:tcp://localhost/~/h2schema/test

Upvotes: 1

Related Questions