I am trying to figure out the different types of generating primary keys for classes that inherit from a superclass, I am using the embedded H2 database, the data is stored in a file. Everything worked well, the entities that I had previously created manually in the database were loaded, but when I tried to save a new entity using Hibernate, I got an error
Table "ID_GENERATOR" not found.
I wonder, should I create the table for "ID_GENERATOR" table generator manually? I thought Hibernate creates it automatically
Here' my superclass:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class FundEvent implements Comparable<FundEvent>{
@Id
@TableGenerator(name = "id_generator")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "id_generator")
protected int id;
@Column(name = "amount")
protected int amount;
@Column(name = "deadline")
protected Date deadline;
@ManyToOne
@JoinColumn(name = "user_id")
protected User user;
//getters and setters
And here's Entity class object of which I'm trying to save:
@Entity
@Table(name = "purchases")
public class Purchase extends FundEvent{
@Column(name = "goal")
private String goal;
@Column(name = "bought")
private boolean bought;
@Column(name = "removed")
private boolean removed;
@Transient
private int activeAmount;
//getters and setters
Do I miss something?
UPD: Here's my hibernate.cfg.xml. Note, i'm not using Spring, just Hibernate
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC Database connection settings -->
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:file:/home/vetal22331122/data_for_purch</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">2</property>
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>
<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">none</property>
<!-- dbcp connection pool configuration -->
<property name="hibernate.dbcp.initialSize">5</property>
<property name="hibernate.dbcp.maxTotal">20</property>
<property name="hibernate.dbcp.maxIdle">10</property>
<property name="hibernate.dbcp.minIdle">5</property>
<property name="hibernate.dbcp.maxWaitMillis">-1</property>
<mapping class="entities.Purchase"/>
<!--<mapping class="entities.Payment"/>-->
<mapping class="entities.User"/>
</session-factory>
</hibernate-configuration>