-->
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.  [ 7 posts ] 
Author Message
 Post subject: WHERE attribute in mapping not used whel object loaded.
PostPosted: Fri Sep 16, 2005 7:37 am 
Newbie

Joined: Thu Aug 25, 2005 3:14 am
Posts: 19
Hi!
I have a simple mapping of my class
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"  assembly ="NHDomainLib" >
   <class name="NHDomainLib.Class1, NHDomainLib" table="Class1" where ="Flag=100">
      <id name="Id" column="Id" unsaved-value="-1">
            <generator class="native" />
      </id>                        
      <property name="Name" column="Name" length ="32"></property>
      <property name="Flag" column="Flag" length ="32" insert="false" update="false"></property>                           
   </class>
</hibernate-mapping>


in mapping included WHERE attribute.
But when i try to get instance of Class1 from DB,
Code:
ISession session= SessFactory.OpenSession();
Class1 c1= session.Load(typef(Class1),5);


value of WHERE attribute in mapping of Class1 - Flag=100 not used in resuted SQLstring.
SQL Profiler return sql string like that:
Code:
exec sp_executesql '
SELECT class10_.Id as Id0_,
   class10_.Flag as Flag0_,
   class10_.Name as Name0_,
   FROM Class1 class10_
WHERE class10_.Id = @p0 ', N'@p0 int', @p0 = 5


in where clause i see only filter by priomary key but not a value of WHERE attribute.

_________________
------------------------------
NETDigitally yours Jericho


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 1:33 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
That's the way Hibernate 2.1 works, but I don't know the exact reason why they did it this way.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 3:40 am 
Newbie

Joined: Thu Aug 25, 2005 3:14 am
Posts: 19
sergey wrote:
That's the way Hibernate 2.1 works, but I don't know the exact reason why they did it this way.


But I may beleave that this behavior of NH cat be changed in future or not? :?

_________________
------------------------------
NETDigitally yours Jericho


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 7:16 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Is this only occurring when you do a get or load by id? Is there where statement applied if you use the criteria API?

It seems like the where clause should always be applied. I can think of an instance where you may have a deleted flag in your table because you don't want to actually delete the object for auditing purposes. If you set the where clause to where="Deleted <> 1" you would expect to never be able to get items that were flaged as deleted.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:39 am 
Newbie

Joined: Thu Aug 25, 2005 3:14 am
Posts: 19
jnapier wrote:
Is this only occurring when you do a get or load by id? Is there where statement applied if you use the criteria API?

It seems like the where clause should always be applied. I can think of an instance where you may have a deleted flag in your table because you don't want to actually delete the object for auditing purposes. If you set the where clause to where="Deleted <> 1" you would expect to never be able to get items that were flaged as deleted.


Hi! You right, when i use criteria API WHERE clause include in sql DB query. But when load object by Id sess.Load(....,id) where clause is omited. This is slightly confuse me. :( But if this behavior "by design" as said sergey, then I need unfortunately to refactor my DAO code.

_________________
------------------------------
NETDigitally yours Jericho


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:39 am 
Senior
Senior

Joined: Thu Jun 02, 2005 5:03 pm
Posts: 135
Location: Paris
Quote:
It seems like the where clause should always be applied. I can think of an instance where you may have a deleted flag in your table because you don't want to actually delete the object for auditing purposes. If you set the where clause to where="Deleted <> 1" you would expect to never be able to get items that were flaged as deleted.


That, in fact, is exactly the way I use it. It's been frustrating for me since I have to implement this value into the object itself so I can check it after a Load or Get.

*sigh* :)

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 2:00 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Can Nhibernate map to a view? If so, using a view may be the best solution to restrict items flag as deleted from being returned. This way it wouldn't matter which query method you used and you wouldnt have to set the where attribute.


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