-->
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.  [ 3 posts ] 
Author Message
 Post subject: criteria.add(example) / ... where {1=1}
PostPosted: Tue Feb 14, 2006 11:14 am 
Newbie

Joined: Wed Jan 04, 2006 8:49 am
Posts: 2
Query By Example not working consistently (for me!).

I am reverse engineering from DB schema. The first code-excerpt works but the second one doesn't work as I would expect.

EXCERPT#1: Works
Code:
     acc = new TAccount();
        acc.setDeletedFg('N'); // this is a char in the generated DTO
            Criteria crit = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(TAccount.class);
            Example example = Example.create(acc);

            String[] excludeProperty = new String[3];
//each of these 3 entries are chars in the generated DTO
            excludeProperty[0] = "mtmEnabledFg";   
            excludeProperty[1] = "autoCloseOutFg";
            excludeProperty[2] = "tradingEnableFg";

            for (String exclude : excludeProperty) {
                example.excludeProperty(exclude);
            }
            crit.add(example);
   



This successfully fetches the correct number of rows. The generated SQL is

Quote:
Hibernate:
select
this_.ACCOUNT_ID as ACCOUNT1_0_0_,
this_.MTM_ENABLED_FG as MTM2_0_0_,
this_.DELETED_FG as DELETED3_0_0_,
this_.CREATED_DTS as CREATED4_0_0_,
this_.LAST_UPDATED_DTS as LAST5_0_0_,
this_.AUTO_CLOSE_OUT_FG as AUTO6_0_0_,
this_.STAMM as STAMM0_0_,
this_.ACCOUNT_NM_TXT as ACCOUNT8_0_0_,
this_.TRADING_ENABLE_FG as TRADING9_0_0_,
this_.STAMP as STAMP0_0_
from
T_ACCOUNT this_
where
(
this_.DELETED_FG=?
)


EXCERPT#2: Doesn't work as I'd expect
Table TMtsCcyCategory has a composite primark key clas TMtsCcyCategoryId made up of SCHEME_ID and CCY_CD.

Code:
    MtsCcyCategoryDAO mtsCcyCategoryDAO = DaoFactory.getInstance().getMtsCcyCategoryDAO();
               
        TMtsCcyCategory cc = new TMtsCcyCategory();
        TMtsCcyCategoryId id = new TMtsCcyCategoryId();
        id.setSchemeId(new Long(2));
        cc.setId(id);
   
           Criteria crit = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(TMtsCcyCategory.class);

           
           Example example = Example.create(cc);
           String[] excludeProperty = new String[4];

            excludeProperty[0] = "ccyCd";
            excludeProperty[0] = "standardPct";


            for (String exclude : excludeProperty) {
                example.excludeProperty(exclude);               
            }   
     
            crit.add(example);

           System.out.println("the size =" + crit.list().size());
          }


The generated SQL is

Quote:
Hibernate:
select
this_.SCHEME_ID as SCHEME1_38_0_,
this_.CCY_CD as CCY2_38_0_,
this_.STANDARD_PCT as STANDARD3_38_0_,
this_.HOLIDAY_PCT as HOLIDAY4_38_0_,
this_.STAMP as STAMP38_0_
from
T_MTS_CCY_CATEGORY this_
where
(
1=1
)



I can't figure out why this query by example doesn't fetch TMtsCcyCategory for which the TMtsCcyCategoryId SCHEME_ID is equal to 2. Do you know why?

BTW, I looked at using net.sf.expression.Expression but to be honest I don't really know why there is a seperate packaging structure (over and abobe the org.hibernate one).



Hibernate version: 3.1.2

Name and version of the database you are using: Oracle 10g


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 12:34 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
the net.sf.hibernate packages are from the 2.x versions of Hibernate. If you're seeing them in your testing, you must have an old jar file in your classpath.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: refer to post http://forum.hibernate.org/viewtopic.php?t=938
PostPosted: Tue Feb 14, 2006 12:40 pm 
Newbie

Joined: Wed Jan 04, 2006 8:49 am
Posts: 2
Thanks. The only reference I saw to net.sw.hibernate was on a web tutorial.

As regards the initial query I found a relevant post...

http://forum.hibernate.org/viewtopic.php?t=938036


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