In chapter 3 (you can read it online) we use the Track table to insert some data and to query data.
We use CreateTest to create and QueryTest to query data. Some simple adaptions are necessary:
- change package name of hibernate classes to org.hibernate
- replace the use of the all-attributes-as-parameters-constructor with Java-Bean style use of empty constructors and setters
- change the type of „volume“ attribute from short to java.lang.Short
Here is the changed part of CreateTest.java:
- Track track = new Track();
- track.setTitle("Russian Trance");
- track.setFilePath("vol2/album610/track02.mp3");
- track.setPlayTime(Time.valueOf("00:03:30"));
- track.setAdded(new Date());
- track.setVolume(new Short((short)0));
- session.save(track);
- track = new Track();
- track.setTitle("Video Killed the Radio Star");
- track.setFilePath("vol2/album611/track12.mp3");
- track.setPlayTime(Time.valueOf("00:03:49"));
- track.setAdded(new Date());
- track.setVolume(new Short((short)0));
- session.save(track);
- track = new Track();
- track.setTitle("Gravity's Angel");
- track.setFilePath("vol2/album175/track03.mp3");
- track.setPlayTime(Time.valueOf("00:06:06"));
- track.setAdded(new Date());
- track.setVolume(new Short((short)0));
- session.save(track);
QueryTest needs only substitution of hibernate package names.
I also created a ant-target called „clean-db“ which deletes the entire schema in order to avoid multiple insertion of the same data as well as an ant-target called „clean“ which simply deletes the „classes“-folder.
- <target name="clean-db" description="deletes schema of DB.">
- <delete>
- <fileset dir="${data.dir}">
- <include name="**/*"/>
- </fileset>
- </delete>
- </target>
- <target name="clean" description="clean ${class.root}">
- <delete dir="${class.root}"/>
- </target>
So now you can say
ant clean-db clean schema codegen ctest qtest
and you get a clean db with a new schema, freshly generated code, test data generation and query test – in one command.