-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using Hibernate When Deletions Should Not Delete
PostPosted: Tue Mar 22, 2005 3:28 pm 
Newbie

Joined: Tue Mar 22, 2005 3:18 pm
Posts: 4
Location: Pennsylvania, USA
Design Question

I am currently evaluating Hibernate to see how it can cope with legacy database designs. In some of my database tables rows shouldn't be deleted but should have an 'end timestamp' value set. This means that a new object may be saved but it already exists in the database and should actually be updated.

I have a solution by implementing Lifecycle and setting the required behaviour, eg onDelete sets the 'end timestamp', does an update and vetos the deletion.

I don't really want persistent code in the POJO and so I looked at using an Interceptor. I can't see anyway to veto the default behaviour though.

Are there any other options for solving this problem? I'm currently looking at version 2.1 but I'm happy to move to version 3.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 4:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi,
all this is possible, prefer hibernate 3 and custom sql

refer to http://blog.hibernate.org/cgi-bin/blosx ... tions.html
you'll find examples

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 4:50 pm 
Newbie

Joined: Tue Mar 22, 2005 3:18 pm
Posts: 4
Location: Pennsylvania, USA
I've had a look at using custom SQL but I don't think it solves the problem for me. I can change the delete to perform an update instead but what about when someone tries to save a new instance with the same key value? I currently deal with this by implementing lifecycle and doing an update instead of a save if necessary. I'd really rather not use the Lifecycle - are there any other options?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 4:59 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
event listener?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 5:06 pm 
Newbie

Joined: Tue Mar 22, 2005 3:18 pm
Posts: 4
Location: Pennsylvania, USA
I thought about an Event Listener too. Can I listen for save events and then send them onto an update event instead? How would I do that?

Another alternative would be to have a stored procedure called from a create custom SQL I guess. Although I'd rather not do that as it starts to hide functionality.

I'm trying to come up with the simplest solution possible as I'm doing a comparison of Hibernate, JDO and EJB and how they handle badly designed (but far too common) database schemas.

Thanks for all of your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.