-->
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.  [ 6 posts ] 
Author Message
 Post subject: session.load(Obj obj) matching only obj.someProperty='value'
PostPosted: Tue Aug 30, 2005 9:52 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
I have some domain object mapped to a table in db, which has 'deleted_flag' property, designating whether record is logically deleted or not.
I want my application consider only 'not-deleted' objects from database, so that it will never be possible to load object with its deleted_Flag=true.

At the moment I have to run HQL, similar to the following:
"from MyObject obj where obj.deleted_flag = false and obj.id = ?'.

What I need to change in object mapping xml so that the same operation can be done thru simple session.load(MyObject.class, new Long(id) method?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 3:36 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
The discriminator may do this kind of thing.

You could look at that article : http://www.onjava.com/lpt/a/6092

or the section 6.1.6 and 10.1.3 of the documentation:

6.1.6. discriminator

The <discriminator> element is required for polymorphic persistence using the table-per-class-hierarchy mapping strategy and declares a discriminator column of the table. The discriminator column contains marker values that tell the persistence layer what subclass to instantiate for a particular row. A restricted set of types may be used: string, character, integer, byte, short, boolean, yes_no, true_false.



Etienne


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 3:40 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
You should have a look at Hibernate filters:
http://www.hibernate.org/hib_docs/v3/re ... e/#filters

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 5:20 pm 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
Sven, I was considering the filters in Hibernate 3, however i found that filter is applied only to the object that is selected, not to its child/nested objects, i.e., and I don't know how to configure filter for inner object in general manner, so that it could be applied to it as if it will be retrieved along or in parent-child relationships.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 10:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
you define the filter on the child collections also...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 5:41 am 
Beginner
Beginner

Joined: Mon Sep 22, 2003 5:18 am
Posts: 28
So, in general, I should paste filters whenever I need to apply them in class mapping file only
Is there any way to use a kind of inheritance of filters from child classes mapping ?


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