-->
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.  [ 4 posts ] 
Author Message
 Post subject: Deleting Objects
PostPosted: Thu Dec 29, 2005 10:36 pm 
Beginner
Beginner

Joined: Thu Dec 01, 2005 12:53 am
Posts: 21
Hibernate version: 3.0

I have certain entities that I don't want to be removed from database when delete is called on them rather they should set some column like isactive = 0

is there any better way to do it other than putting custom logic to set isactive = 0 in delete methods of DAO classes?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 11:00 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Use the <sql-delete> tag in your mapping to write custom code which updates the relevant field. Or use database triggers.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 01, 2006 2:12 pm 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
Apart from that you should modify your DAO layer so it works something like this:

Code:
public MyEntity load( Long id ) {
    MyEntity entity = session.get( MyEntity.class, id );
    if ( !entity.isActive() )
      return null;
}


Otherwise your presentation logic will be able to load entities that have been "deleted"


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 01, 2006 5:38 pm 
Beginner
Beginner

Joined: Thu Dec 01, 2005 12:53 am
Posts: 21
Yes ouzo... but I like Hibernate filters very helpful to do this for me. And the fact that hibernate doesn not apply filter when we load entities by id is really helpful. We never load starting entities in our applicaitons with IDs so we never happen to read an inactive entitry whose record has isActive set to zero.


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