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.
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.
Related
In my project we are using oracle database as the main application db and H2 as in memory database to run only the integration test cases. Oracle db has many functions which are of the structure "schema.package.function()". The problem is, i'm not able to recreate the same function in H2 for integration test cases as H2 treats it in the form of "dbname.schemaname.functionname()".
for example : When code runs with oracle db , "SELECT MDM.NEXT_KEYS.NEXT_REF_SOURCE_KEY from dual" works. During integration test case on H2, it throws error "DB MDM not found". So i set the db name as MDM and schema name as NEXT_KEYS in h2 setup.It worked. But my next function PAYERS.KEY_TRANSLATIONS.CORE_ENHANCED_DESC_4_KEY fails now saying "DB PAYERS not found".
Changing the oracle functions is out of the equation as they are used by multiple teams.
If this is not possible with H2 , can you suggest a good alternate in-memory db for spring boot
Appreciate your help !
I was able to fix the issue. Adding the solution link here so that it might help someone
Setting this flag IGNORE_CATALOGS=TRUE fixed the issue. When it is enabled, name of catalog (database) is ignored.
spring.datasource.url = jdbc:h2:mem:testdb;MODE=Oracle;IGNORE_CATALOGS=TRUE
Refer the below link https://github.com/h2database/h2database/issues/2893
I deployed a simple Jpdl (JBPM4.4) and when i check the jbpm database. I found entries in JBPM4_DEPLOYMENT, JBPM4_DEPLOYPROP tables but not in anyothe table.
I want to understand when the entries goes into the other tables of jbpm database.
You will find the database scripts for a lot of the supported
databases in the DB subproject. The database scripts for PostgreSQL
are found in the folder '${JBPM_SDK_HOME}/jbpm-db/build/mysql/scripts.
The creation script is called 'postgresql.create.sql'. Using
DBVisualizer, you can load this script by switching to the 'SQL
Commander' tab and then selecting 'File->Load...'. In the following
dialog, navigate to the creation script file.
Resource Link: https://docs.jboss.org/jbpm/v3/userguide/thejbpmdatabase.html
You will also get mysql data import related info step by step in this link.
Was wondering, what steps am I missing to get a jdbc embeded h2 database working in my play application? Following these docs.
So far editted Application.conf file to contain this:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:databases/test"
db.default.user=test
db.default.password="testtest"
Next I created a libs directory and added the jar file
h2-1.3.174.jar
Is this necessary or does the provided driver handle all types of h2 databases (embeded and server - I know it handles in memory)?
Now in the controler how can I access the database? Do I have to start/shutdown the database?
I know I can get connections from the getConnection() method in play.db. But everytime I execute a statement through this connection I get an exception saying no data is available. If I then check - looks like directory
databases/test
was not created so no database files exist.
What am I missing?
H2 works out of the box. Just create a new project in the terminal.
Otherwise, to your listing:
I think you should change db.default.url="jdbc:h2:databases/test" to db.default.url="jdbc:h2:mem:play"
don't need to create lib directories. It's all handeled by the build in dependency mgmt sbt
Just use the model objects and call save/update. No need to call start/shutdown
you are in a framework, it's all there ready for you...
I think you should start reading the documentation from the beginning to the end and examine the example applications. It's all there what you are looking for.
In addition to myborobudur's answer I'll only mention, that you don't need to use memory database, as you can for an instance use file storage (Embedded) or even run H2 as a server and then connect to it with TCP in Server Mode... Everything is clearly described in H2 documentation.
I have 2 projects in Eclipse.
The first project calls a method from the second project handing it an object the second project shall write into an existing SQLite Database residing in the second project.
However, I get the following error:
opening db: 'tomato.db': Zugriff verweigert
Zugriff verweigert is German for access denied.
How can I allow the db access from the first project to the database file tomato.db residing in the second project?
Solution
I use sqlite-jdbc from xerial.
In their tutorial they get the database connection with this line:
connection = DriverManager.getConnection("jdbc:sqlite:yourdatabasefile.db");
However, this doesn't work from another project in Eclipse.
The solution is actually pretty trivial:
connection = DriverManager.getConnection("jdbc:sqlite:C:\\path\\to\\your\\database\\file\\yourdatabasefile.db");
Another solution is to use the in-memory sqlite database like this:
connection = DriverManager.getConnection("jdbc:sqlite::memory:");
Hope this helps.
I successfuly embedded javadb in my application using the classpath ,but here's the problem : I want hibernate to be able to work with the database,but I always get an error in netbeans sayng "enable to establish connection ".
AnyHelp please ?
The URL for a local HSQLDB database is jdbc:hsqldb:file:file_path_name The file_path_name is usually an absolute path with a name at the end. The database engine will then create a few files with the given name, but predefined extensions. An example of this is: jdbc:hsqldb:file:/mydata/mydb which will produce mydb.properties , mydb.script and a couple other files in the /mydata directory.