The moose likes Object Relational Mapping and the fly likes DOA or not DAO this is the question? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "DOA or not DAO this is the question?" Watch "DOA or not DAO this is the question?" New topic
Author

DOA or not DAO this is the question?

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Hey,

One of the greatest things in hibernate that you dont need to deal with DB.

you are wotrking with object, like without the need to be aware to the DB,

but this is not exactly true.

For exmaple :

I have User with OneToOne to City.

In simple java code if i want to delete city all i need to do is:

city = null;

but in hibernate this is not enough. You need to delete all the reference to city, so you can not write just java code without the need to be aware to the ORM layer.

I thought to solve it by forbid to use in set null and obligant the developer to use in DAO for operations like this.

How do you guys solve issues like this?

Thank you
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

"city = null;

but in hibernate this is not enough. You need to delete all the reference to city, so you can not write just java code without the need to be aware to the ORM layer."

Actually I would say that is a Java thing and not a ORM or Database thing.

If I have references to an object on the heap, say three references, then doing just city=null will not delete the city object, you still have two other references that will keep that object from being deleted, aka garbage collected. So you would still have to do the same thing with or without Hibernate.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
So, how do you solve it?

By DAO?
By generic mechanism that will serach for the references and delete them?
By giving the responsibility to do this to the developer?

Any suggestions will be welcome

Thank you
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

You solve it the same way you would solve it without ORM. You set all the references to null through code if you want to make sure the object is available for garbage collection.

Which class it is in depends on where it makes most sense for that particular problem. Maybe it is a DAO maybe it is in some Business Logic class, I can't say that one is better than the other, because it is use case driven.

Mark
 
 
subject: DOA or not DAO this is the question?
 
Threads others viewed
i need code for jdbc framework?
null pointer exception in spring with hibernate
Hibernate or JDO or EJB or Castor or even others ?
Hibernate & J2EE
how to inject DAO with Spring???
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture