Posts Tagged Eclipse

My first TDD or why NetBeans sucks

Tags: , , , ,

This week was very intensive in terms of education. First, a three-day training about Test-Driven Development at Pragmatists, then presentation about Vaadin by Bartek Kuczyński at Warsaw JUG meeting.

However, in this post I will focus on the most interesting thing, Test-Driven Development training and what I learnt there. The whole event lasted three days and in my opinion it was very effectively spent time. The only thing I didn’t like was a little too long theoretical introduction to the TDD and testing, but it is probably the feature of most trainings that the first chapter must be about only a theory. Fortunately, later it started to be much, much more interesting and the workshops began. They consisted of  pair programming, writing tests, refactoring to patterns, mocking with Mockito, everything I expected from this training when I had enrolled. And everything in the amount that helped be to understand philosophy of software development with TDD on the practical side. Only a basic level, however, because to do it smoothly and quickly I have to spend a lot of time on Test-Driving and learning. But I did the first step.

Unfortunately at the beginning of this training it appeared that my lovely IDE (NetBeans) isn’t a natural-born IDE for TDD. And what’s the problem? NB isn’t smart enough when we are coding and trying to generate code by intention. For example, let’s compare process of creating testing method and how two IDEs: Eclipse and NetBeans are helping us in the following scenario: Continue reading this post …


Be Sociable, Share!

Eclipse and problem with auto generated equals()

Tags: , , ,

Lately my colleague from job encountered following problem:

JSF table <rich:dataTable> was using HashMap to represent data. This Map contained objects collected from the database. After saving new objects to Db and table refresh it showed objects completely different from what we expected. After few hours of searching for a bug in our code or in JSF code it appeared that problem lied in other place.

Eclipse generates equals method checking if classes of compared objects are the same:

...
іf (getClass() != obϳ.getClass()) {
    return fаlse;
}
...

ant such behavior combined with Hibernate can cause some problems because very often while loading data from Db instead of object of our class Hibernate creates proxy object extending base class we are loading. And then equals method comparing getClass() returns false causing strange HashMap behavior. Solution is very simple: instead of getClass() you should use instanceof.

Additionally, as I read in comment on Proxorkut blog, if we use lazy loading in entity classes we should use getXXX() methods in equals() and hashcode() to get variable values because if we try to get them directly from the fields, Hibernate might not initialize them before we try to use them.


Be Sociable, Share!