Tuesday, January 29, 2008

Java Bug Date equals?

Who would have thought that the following test would fail:

private Date getDate14April() {
Calendar calendar = Calendar.getInstance();
calendar.set(2007, 3, 14, 15, 30); // 14 april 15:30
return calendar.getTime();
}

public void testCompareDate() {
Date date = getDate14April();
for (int i=0; i < 100; i++) {
assertEquals(getDate14April, date);
}

Stacktrace (edited brackets):

junit.framework.AssertionFailedError: 60 expected: [Sat Apr 14 15:30:40 CEST 2007] but was:[Sat Apr 14 15:30:40 CEST 2007]
at org.westen.act.document.TestTemplateManager.testCompareDate(TestTemplateManager.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


JavaDoc of Date.equals:
Compares two dates for equality.
The result is true if and only if the argument is not null> and is a Date object that represents the same point in time, to the millisecond, as this object.

Hmm, I would have though that the milliseconds would have been initialized to 0 when I create a date object.





Hibernate many-to-many & inverse

I had the problem that two entities A and B had a many-to-many relation but deleting an object a resulted in a constraint violation because the object was used by an object b.

To my surprise fiddling with the inverse="true", inverse="false" and cascade="none" fixed the problem.

My understanding is that deleting an object always deletes the row from the join table. (cascade="none"). Setting cascade to "delete" will also force the deletion of the object(s) on the other side.

However why inverse="true" and "false" make a difference I do not understand. You would assume that specifying one would be enough and imply the other. Apparently there is more to it than I understand. Needs a follow up...

So I'm not the first one to run into this. Found this blog "Hibernates bizarre interpretation of inverse". He basically says that inverse tells Hibernate which side of the relation to ignore. Although this does make complete sense to me, it fits my problem.

Hmmmm

Saturday, January 19, 2008

GWT-EXT

The last few weeks i've been struggling with GWT-Ext 1. Conclusion: the lay-out capabilities of GWT-Ext 1 are poor.

For example a table-layout is not possible. When using a form you can only place a limited number of widgets on it. Separate label widget is not present.

Ext v2 has much richer lay-our support. So we have to wait for GWT-Ext 2....