My Dao layer works fine with the MySql. When I try to unit test the same with the in memory db (HSQLDB) I am not able to persist data. My entity is defined as follows
public class Api {
@Id
@Column(name = "api_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int apiId;
When trying to persist the id is not auto generated. It is passed as null.
18:05:52.071 [main] DEBUG org.hibernate.SQL - insert into api (api_id, description, version) values (null, ?, ?)
18:05:52.076 [main] DEBUG o.h.e.jdbc.spi.SqlExceptionHelper - could not prepare statement [insert into api (api_id, description, name) values (null, ?, ?)]
My hibernate properties are
Properties properties = new Properties();
properties.setProperty(ApiConstants.HIBERNATE_DIALECT, "org.hibernate.dialect.HSQLDialect");
properties.setProperty(ApiConstants.HIBERNATE_DRIVER_CLASS, "org.hsqldb.jdbcDriver");
properties.setProperty(ApiConstants.HIBERNATE_CONN_URL, "jdbc:hsqldb:mem:apicloud");
properties.setProperty(ApiConstants.HIBERNATE_CONN_USER, "sa");
properties.setProperty(ApiConstants.HIBERNATE_CONN_PWD, "");
properties.setProperty("hibernate.archive.autodetection", "class,hbm");
properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
properties.setProperty("hibernate.show_sql", "true");
Schema is created every time the unit test is triggered. Create statement is issued as follows.
18:05:51.995 [main] DEBUG org.hibernate.SQL - create table api
(api_id integer generated by default as identity (start with 1),
description varchar(255), version varchar(255), primary key (api_id))
Let me know if I am missing something.
The problem got solved when I updated the HSQLDB version to 2.2.9.
https://forum.hibernate.org/viewtopic.php?f=1&t=1043498&p=2490106#p2490106
Pradeep.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.