Hibernate and H2 n JavaFX app, not creating tables

I want to include a database to my JavaFX app. I chose h2 and configured hibernate to use with it. The problem is that it doesnt' create tables from entities like it's supposed to. What I did, I have these dependecies:


I have this hibernate.cfg.xml configuration file stored in the resources folder:

<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"

    <property name="connection.driver_class">org.h2.Driver</property>
    <property name="connection.url">jdbc:h2:file:./database
    <property name="connection.username">...</property>
    <property name="connection.password">...</property>
    <property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
    <property name="hibernate.show_sql">true</property>
    <property name="">update</property> // setting to create also didn't help
    <mapping class="my.package.model.TestEntity"/>

TestEntity is annotated with needed annotations like @Entity:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Table(name = "test_entity")
public class TestEntity {

  @Column(name = "test")
  private String test;


But it's not working, the database is getting created, but there is no TestEntity table. What could be the problem?


  • So the problem was with 2 things:

    1. It should import jakarta.persistence.Entity not import javax.persistence.Entity;
    2. Turns out you can't connect to H2 file normally trough IntelliJ idea. So I have to download h2 gui, launch it and only after that I was able to see the content of the database. Also I needed to run h2 with AUTO_SERVER=TRUE.