• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOA or not DAO this is the question?

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic