-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Cleaning up bad data via hibernate?
PostPosted: Tue Oct 28, 2003 4:56 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
We have a data load process that happens outside of hibernate. In some of our relatioships it is possible that the child object's reference to the parent be invalid after the data load. (We turn off the FK constraints in Mysql during the load to do this)

All we need to do is delete the objects that contain these invalid references. I would prefer to do the delete in hibernate so that we can take advantage of cascading deletes. A lot of these objects have subclasses or other relationships and doing all the deletions via jdbc is quite a maintenance nightmare. (i.e everytime we add a new subclass we need to add another delete statement in the dataload cleanup, ugh!)

However when I try and delete the objects via Hibernate i get

Caused by: net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: 2

this is caused by the invalid reference. So it's like "I know it doesn't exist thats why I am trying to delete it!"

Is there anyway to achieve this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 5:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You could use a UserType.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 7:51 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
ok I am interested. I have looked through the doc, and API. Is there an example somewhere on this? Not sure I follow how this solves my problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 7:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
well, to be honest its probably not practical anyway,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 8:08 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
wha??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 2:21 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
gavin wrote:
well, to be honest its probably not practical anyway,


This is all you are going to give me? Well in my best Gavin King impression.... "WTF does that mean?"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 2:37 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
if you can not validate/transform data before import (It can be too slow in some cases) drop FK and ignore invalid rows. I do not think hibernate can clear garbage faster than import procedures.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 3:00 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
baliukas wrote:
if you can not validate/transform data before import (It can be too slow in some cases) drop FK and ignore invalid rows. I do not think hibernate can clear garbage faster than import procedures.


The data that we are importing is good. We are basically importing our product model. The deal is that before we re-import we delete the current product model in the DB, and then import new one. So it is possible that some of the products do not exist after the re-import. We then need to clean-up the objects that are refencing these non-existent products. We disable FK's at start of load and then enable them after all clean-up.

The issue is we want to use Hibernate delete to do clean-up to take advantage of cascading and object heirarchies. Otherwise clean-up becomes maintenance nightmare through JDBC.

So why is it that Hibernate must complain about invalid references during a delete? We are only trying to get rid of that which Hibernate is complaining about.

Does this make sense? This seems like a valid scenario, is nobody else doing something similar?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 3:28 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I think your way is OK and you do not need to load objects to memory for delete.
I am not sure new mySQL versions support subqueries, but it must be a very trivial dynamic query:

" delete from " + table1 +
" where " + parentId +
" not in ( select " + id + " from " + table2 + " ) "


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 3:46 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
Thank you for your replies baliukas. However you don't seem to be grasping the issue.

We don't want to do a delete in SQL.

Not because we can't figure out the syntax. But because some of the objects we will be deleting are part of object relational heirarchies and also have cascading relationships with other objects. That means everytime you add a new relationship and add cascade="all", we want to be done. We don't want to have to then go back and synch up the SQL to delete this new relationship as well. This becomes a maintenance nightmare, and will probably only get done about 50% of the time. Whereas hibernate knows about all of the relationships and which to cascade. So it would work best for us if we could use Hibernate to delete these objects.

Make sense? Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 5:50 pm 
Newbie

Joined: Tue Oct 28, 2003 4:43 pm
Posts: 13
I created a JIRA imporvement

http://opensource.atlassian.com/project ... key=HB-434


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 29, 2003 7:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I just don't think that this is really a good use case for ORM.

Yes, it is possible to use a UserType to avoid the nullcheck that Hibernate does, but this would require screwing up all your mappings.

I might be wrong.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.