-->
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/Query bY example supports inheritance?
PostPosted: Fri Jan 05, 2007 1:30 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1


Hi all,
i have an hibernate app inw hich i have 4 classes, and i am using a table per class hierarchy.
I am using Criteria/QueryByExample in my tests,as well alsnamed query

All namedQuery works fine, but all tests in which i am using Criteria/QueryByExample (on the same data) are failing......

Before i post any code (i ms till investigating), does Criteria/QueryByExample supports inheritance in Table per class hierarchy?

here's code i m using for the query

Code:
public List findByExample(Object exampleInstance) {

System.err.println("Creating criteria for class " + exampleInstance.getClass().getName());
        Criteria crit = getSession().createCriteria(exampleInstance.getClass());
        Example example =  Example.create(exampleInstance);
       
        crit.add(example);
        return crit.list();
    }


any hints on why critera queries are failing?

thanks and regards
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 10:37 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
hello,
i figured out actually what was the problem.. thing is that in QBE itdoes an SQL selecting all properties of the exampleInstance... i was expecting that if i populate an example instance with 3 properties out of 8, it will do a sql using those 3 properties instead of all 8..
any idea on how to accomplish that using QBE? is it possible? i posted another thread.... any comments are welcome

thanx and regards
marco


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 11:18 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
Correction...
actually a QBE is owrking fine with partially populated objects (i m using iwht another object that is not inherited)

It looks to me that the problem might be related with the mapping strategy i am using.
Here are two different examples, one works and the other does not

this is Configurator class, no inheritance at all, i am populating just one property, xsltPATH
here's generated query
Code:
Hibernate: select this_.id as id0_0_, this_.command as command0_0_, this_.mappin
gFile as mappingF3_0_0_, this_.normalizer as normalizer0_0_, this_.translator as
translator0_0_, this_.validator as validator0_0_, this_.xsltPath as xsltPath0_0
_, this_.site as site0_0_ from Configurator this_ where (this_.xsltPath=?)


And here's the example tha ti so nt working. I am using a table per class hierarchy. i have one object (TransferRecordImpl) and 3 subclasses (ReplenRequest, ExpectedReceipt and ReceiptConfirmation).
I created a ReplenRequest and populate it iwth only 2 properties, and here's what Hibernate generates as SQL
Code:
Hibernate: select this_.id as id4_0_, this_.creationTimestamp as creation3_4_0_,
this_.status as status4_0_, this_.dlfSiteRef as dlfSiteRef4_0_, this_.transmiss
ionNumber as transmis6_4_0_, this_.transmissionTimestamp as transmis7_4_0_, this
_.interfaceType as interfac8_4_0_, this_.valid as valid4_0_, this_.manualInd as
manualInd4_0_, this_.operatorRef as operato17_4_0_, this_.productRef as productR
ef4_0_, this_.locationRef as locatio10_4_0_, this_.scanDate as scanDate4_0_, thi
s_.scanTime as scanTime4_0_, this_.scanner as scanner4_0_, this_.stockOutInd as
stockOu22_4_0_ from transferrecord this_ where this_.type=0 and (this_.creationT
imestamp=? and this_.status=? and this_.dlfSiteRef=? and this_.transmissionNumbe
r=? and this_.transmissionTimestamp=? and this_.interfaceType=? and this_.valid=
? and this_.manualInd=? and this_.operatorRef=? and this_.productRef=? and this_
.locationRef=? and this_.scanDate=? and this_.scanTime=? and this_.scanner=? and
this_.stockOutInd=?)


So, it is using ALL properties of the exampleInstance (ReplenRequest), and that is why is failing

So, i guess i have only 2 solutions for this case:
1) drop queryBYExample when using table per class hierarchy
2) try to use a different mapping strategy (mayb table per subclass will fix it..)

does anyone suggest any other solution?
I'd love to know why Hibernate QBE behaves that way for table per class inheritance.... anyone could give me a good explanation?

thanks in advance and regars
Marco


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.