I'm using spring 1.01 hibernate 2.1.2 and mysql. I'm trying to run unit tests on my DAOs(load/saving/deleting) which are going well except for saving "native" id-generated objects. Saving "assigned" id-generated objects works well.
For the tests i prepopulate the table with data and even supply ids for "natively" created ids.Here is a sample of sql to populate db. [librarydemo].
Code:
create table reservations (
id BIGINT NOT NULL AUTO_INCREMENT,
book_id VARCHAR(25),
date_made DATE,
member_id VARCHAR(20),
remarks VARCHAR(255),
limit_in_days INTEGER,
primary key (id)
);
Code:
insert into reservations values (1,'1-86100-784-1','2004-04-25','2004-1238','1st reserver',25);
insert into reservations values (2,'1-861002-23-8','2004-04-26','2004-1243','1st reserver',25);
The code snippets in java are as follows
Code:
@hibernate.class table="reservations"
public class Reservation
{
/*
* @hibernate.id
* name="id"
* type="long"
* column="id"
* unsaved-value="-1"
* generator-class="native"
*/
public Long getId()
{
return this.id;
}
. . . .
}