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
Marc E - 30 May 2006 01:29 GMT
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?
> Hello everyone, newbie here. I'm developing an application for a repair
> shop. Customer comes in with a product, gets registered and a receipt
[quoted text clipped - 34 lines]
> Regards,
> hjf
Luke Webber - 30 May 2006 06:22 GMT
> 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?
I'm glad to hear that somebody else agrees with me on that. OTOH, I'm
tracking the Hibernate Annotations project, and that seems to answer all
of those complaints. I think it makes Hibernate look very attractive.
The only thing missing now is a really good book on Hibernate strictly
from the Annotations viewpoint.
Luke
Daniel Rohe - 02 Jun 2006 17:09 GMT
drg schrieb:
> Hello everyone, newbie here. I'm developing an application for a repair
> shop. Customer comes in with a product, gets registered and a receipt
[quoted text clipped - 31 lines]
>
> What do you think? What's the right way to go?
So far I've understood you have Customer <-> City <-> Province. Where as
a Customer lives in a City and a City can contain many Customers. And
you have a City which is located in a Province and on the other side you
have a Province which is an area with some Cities. Hibernate does the
mapping of objects and their relationships to the database, that's why
it's called ORM.
If the user in your application selects a customer Hibernate can
retrieve the complete object tree from Customer to City and Province. If
I had to populate a combo box with cities already in database then I
would add a method to City which retrieves every City from database.
Another case could be the user has already selected a Province and now
you will populate the combo box with Cities in this Province. Here I
would add a method to Province which returns all Cities in it. In each
case the mapping to SQL queries will be done by Hibernate.
HTH
Daniel
drg - 04 Jun 2006 21:30 GMT
> So far I've understood you have Customer <-> City <-> Province. Where as
> a Customer lives in a City and a City can contain many Customers. And
> you have a City which is located in a Province and on the other side you
> have a Province which is an area with some Cities. Hibernate does the
> mapping of objects and their relationships to the database, that's why
> it's called ORM.
Exactly.
> If the user in your application selects a customer Hibernate can
> retrieve the complete object tree from Customer to City and Province. If
[quoted text clipped - 4 lines]
> would add a method to Province which returns all Cities in it. In each
> case the mapping to SQL queries will be done by Hibernate.
yes, but the question is, suppose I have 10000 Cities in a list.
Hibernate would return an array of Cities, and the ComboBox would call
toString() to display them. On the other hand, if I use JDBC, I would
get an array of Strings, which I *think* would be much smaller than an
array of cities. I wonder what kind of performance I'd be losing by
using Hibernate.
But of course, Hibernate simplifies things because the ComboBox can now
return a city (and a province). With JDBC I would need to write a lot
of extra code to do the same thing.
Regards,
Hernan
Daniel Rohe - 05 Jun 2006 08:34 GMT
drg schrieb:
>> So far I've understood you have Customer <-> City <-> Province. Where as
>> a Customer lives in a City and a City can contain many Customers. And
[quoted text clipped - 23 lines]
> return a city (and a province). With JDBC I would need to write a lot
> of extra code to do the same thing.
You can return only the name of the cities with Hibernate (SELECT c.name
FROM com.example.City c).
Daniel