Re: To hibernate or not to hibernate?



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
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?

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
.



Relevant Pages

  • To hibernate or not to hibernate?
    ... or should I use Hibernate to take care of the DB stuff? ... I have a Customer object and can pass data ... Imagine I have a list of cities ... If I populate the JComboBox with a simple array read ...
    (comp.lang.java.databases)
  • populating one combo box based on another
    ... I have a table called state that lists states. ... THis table contains states and then cities within each state. ... I create a form based on the customer table but omit the city and state ...
    (microsoft.public.access.formscoding)
  • dependent combo boxes
    ... I have a table called state that lists states. ... THis table contains states and then cities within each state. ... I create a form based on the customer table but omit the city and state ...
    (microsoft.public.access.forms)
  • Re: check new customer is exist in table
    ... Use a combo box to link the Cities to their states, and a combo box to link ... the customer to the city. ... peculiar habits of having John Smith Senior and John Smith Junior, ... I must check the customer in this table or not before insert it. ...
    (comp.databases.ms-access)
  • Re: To hibernate or not to hibernate?
    ... a Customer lives in a City and a City can contain many Customers. ... I had to populate a combo box with cities already in database then I ... case the mapping to SQL queries will be done by Hibernate. ...
    (comp.lang.java.databases)