1

I am creating a Hibernate project in IntelliJ IDE and trying to hook it up with a H2 database. I created the project based upon this tutorial:

http://www.roseindia.net/hibernate/hibernate4.2/hibernate-example-step-by-step-in-eclipse.shtml

The only change I'm making is the database, instead of MySQL, I'm using H2. However, when I'm trying to run the application, the insertion to the database is shown to have been successful, but there are no signs of any such rows when I open up the database in the H2 console. I've tried many solutions suggested here and elsewhere, including this, this and this. I've tried changing the connection URL of the database in the hibernate.cfg.xml file from a relative path to absolute path, but to no avail. I'm attaching a screenshot of my hibernate.cfg.xml and the relevant portion of the log below. Please help me out with this.

enter image description here

Community
  • 1
  • 1
supriyo_basak
  • 505
  • 1
  • 7
  • 24

1 Answers1

0

your hibernate.connection.url should be something like that jdbc:h2:tcp://localhost/mem:playground I am assuming you are starting the H2 database out of your project, as you are connecting to H2 via console.

dursun
  • 1,861
  • 2
  • 21
  • 38
  • I read somewhere that using "mem" causes H2 to load "in-memory", which as I understood, makes the database lose all table information once it goes out of scope, which is why I didn't use that syntax. Am I correct in assuming this? – supriyo_basak Sep 11 '14 at 10:02
  • if you are not using `mem` then how do you connect to H2 console. – dursun Sep 11 '14 at 10:06
  • I'm just using the H2 Command-line batch file which came with the database download. I'm not connecting to the console from my program. The URL which I use there is jdbc:h2:~/test – supriyo_basak Sep 11 '14 at 10:08
  • then you have two option . use `mem` to connect H2 command-line using connection url jdbc:h2:tcp://localhost/mem:playground . use connection url as jdbc:h2:~/test then close your application open H2 Command line with same connection url and see the results. in this mode you cannot run H2 command-line, and your application at the same time. – dursun Sep 11 '14 at 11:26
  • Thanks dursun, for pointing me down the right path. No, I didn't need to use mem. However, you were right in pointing out that the connection URL should point to a remote database location. So I finally used jdbc:h2:tcp://localhost/~/test and it functioned smoothly. Thanks a lot once again. Cheers.. – supriyo_basak Sep 11 '14 at 13:00