Hi,
Our Dao layer works fine with a mysql backend. How ever when I try to unit test the same using the in memory HsqlDB we are getting the following issue.
Code:
insert into api (api_id, description, name, version) values (null, ?, ?, ?)
the id is actually getting passed as null. Following is my Entity definition
Code:
public class Api {
@Id
@Column(name = "api_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
...
...
...
}
I am creating the database whenever the unit test is triggered using the following configuration
Code:
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:mydb");
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");
return properties;
When i tried to read through, how the table got created , I found the following logs
Code:
create table api (api_id integer generated by default as identity (start with 1), description varchar(255), name varchar(255), version varchar(255), primary key (api_id))
Kindly let me know what I am missing.
Pradeep.