I'm just starting to learn Hibernate, downloaded the current CaveatEmptor example, and found defects in it. There doesn't seem to be a JIRA category for CaveatEmptor defects, so I'll report the issues here and hope they move to someplace they can be repaired permanently.
First, I'm running on a Windows workstation, where runCleanDatabase.sh won't do. Here's a runCleanDatabase.bat that works for me:
====== begin runCleanDatabase.bat =====
Code:
set java_home=c:\jdk1.5.0
if not exist database mkdir database
echo Removing database files...
del /s database\test.*
echo Starting database engine with %JAVA_HOME%\bin\java.exe ...
cd database
%JAVA_HOME%\bin\java.exe -classpath ..\lib\hsqldb.jar org.hsqldb.Server
===== end runCleanDatabase.bat =====
Second, there are defects in the test data which cause the junit tests to fail.
Specifically, when creating new Items, the Calendar manipulations used to create the endDate are creating bad data this week, the last week of 2005. inThreeDays.roll(Calendar.DAY_OF_YEAR,3) gets me to January 2005, which is an invalid endDate if the startDate is today, because according to the ITEM table constraints the startDate must come before the endDate. Changing cal.roll(...) to cal.add(...) solves the problem.
Changes made in TestCaseWithData.java and AuditTest.java:
TestCaseWithData.java about line 85
was
Code:
inThreeDays.roll(Calendar.DAY_OF_YEAR, 3);
Calendar inFiveDays = GregorianCalendar.getInstance();
inFiveDays.roll(Calendar.DAY_OF_YEAR, 5);
Calendar nextWeek = GregorianCalendar.getInstance();
nextWeek.roll(Calendar.WEEK_OF_YEAR, true);
should be
Code:
inThreeDays.add(Calendar.DAY_OF_YEAR, 3);
Calendar inFiveDays = GregorianCalendar.getInstance();
inFiveDays.add(Calendar.DAY_OF_YEAR, 5);
Calendar nextWeek = GregorianCalendar.getInstance();
nextWeek.add(Calendar.WEEK_OF_YEAR, 1);
AuditTest.java line 39+
was
Code:
Calendar inThreeDays = GregorianCalendar.getInstance();
inThreeDays.roll(Calendar.DAY_OF_YEAR, 3);
should be
Code:
Calendar inThreeDays = GregorianCalendar.getInstance();
inThreeDays.add(Calendar.DAY_OF_YEAR, 3);
and all the unit tests now pass.
Thanks for the example app. I'm finding it very informative to work through.