Re: To hibernate or not to hibernate?



I'm interested in hearing more on this, too. Having programmed JDBC for a
lot of years, I agree that the plumbing (all the try/catch/finally and
connection-drudgery) business is ugly, but hibernate and their O/R ilk seem
like so much work and seem, from the outside, to be a maintenance nightmare.
No?


"drg" <drgenio@xxxxxxxxx> wrote in message
news:1148836533.072268.78850@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello everyone, newbie here. I'm developing an application for a repair
shop. Customer comes in with a product, gets registered and a receipt
is printed out. I did it on Access five years ago and it's been working
since then. But now I want to add a few features to it and I'll have to
rewrite it from scratch so I chose Java for the job.

But as it's a database I have a problem now. Should I go with plain old
JDBC access, or should I use Hibernate to take care of the DB stuff?
The thing is, I tried hibernate to do the work. I had to create a
"Customer" object, who lived in a "City" object, which in turn was
located on a "Province/State" object. This approach is interesting. If
I develop a web service, I have a Customer object and can pass data
easily, but the problem is the number of auxiliary objects I have to
create. I mean, my relational model is OK, but either I don't
understand it, and I have that many Java objects, or the system is just
that complicated. I know things may look complicated at first but in
the future it can save me a lot of time. I like the fact that I can
just call customer.saveOrUpdate() and have it saved, instead of having
to define an interface and implement it for each object. But my own
custom (more limited) saveOrUpdate() method won't need the auxiliary
City and Province objects (I would use String city and int cityId, for
example).

This worries me in one particular case. Imagine I have a list of cities
in a JComboBox. If I populate the JComboBox with a simple array read
from the database, it's fast and low on memory. But if I call Hibernate
to provide me with an array of Cities, I'm afraid I'll have a little
memory hog (there won't be that many cities anyway, but that's just to
make an example). Am I right, or I'm missing something here? I think I
should read the database to populate the JComboBox and then read the
selection from the DB with Hibernate to get the City object. But I
think that won't be pretty, and I also will lose Hibernate's DB
independence.

What do you think? What's the right way to go?

Regards,
hjf



.