-->
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.  [ 5 posts ] 
Author Message
 Post subject: polymorphic query builder
PostPosted: Wed Mar 02, 2011 1:02 pm 
Newbie

Joined: Thu Jul 19, 2007 11:21 am
Posts: 12
Hello,

I have a problem building a query for an abstract entity.

the mapping is very simple:

Code:
public abstract class BaseClass ... (has some indexed fields)



Code:
@Indexed
public class ConcreteClass extends BaseClass ...(also has some indexed fields)


constructions such as :

Code:
this.fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(ConcreteClass.class).get();


work just fine.

I have just tried today to build a QB on the abstract class like this:

Code:
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(BaseClass.class).get();


it triggers an error, first lines:

Code:
java.lang.IllegalArgumentException: Entity for which to retrieve the scoped analyzer is not an @Indexed entity: *path/to/BaseClass*
   at org.hibernate.search.impl.ImmutableSearchFactory.getAnalyzer(ImmutableSearchFactory.java:284)
   at org.hibernate.search.query.dsl.impl.ConnectedQueryContextBuilder$HSearchEntityContext.<init>(ConnectedQueryContextBuilder.java:55)
   at org.hibernate.search.query.dsl.impl.ConnectedQueryContextBuilder.forEntity(ConnectedQueryContextBuilder.java:46)


I don't explicitly set any analyzer on entities, I set a default one in hibernate properties:
Code:
<property name="hibernate.search.analyzer">org.apache.lucene.analysis.standard.StandardAnalyzer</property>


Is what i am trying to achieve illegal or is something wrong with my technique? If the former i guess i can workaround it by adding all concrete entities to QB, however it would be nice to be able to use polymorphism here.

[EDIT] Using hibernate-core v.3.6.0.Final and hibernate-search v.3.3.0.Final and hibernate-commons-annotations v.3.2.0.Final and lucene-core v.3.0.3

thanks,
val


Top
 Profile  
 
 Post subject: Re: polymorphic query builder
PostPosted: Thu Mar 03, 2011 9:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi Val,
It's a use case I have not foreseen and that should be valid as long as you agree that in this case on only can query fields hosted on BaseClass and not the specific fields of its subclasses.

I've created http://opensource.atlassian.com/project ... SEARCH-703 to capture it.

I am in the middle of a humongous refactoring but if you could write a unit test showing the issue and making it a pull request on GitHub, I will try to fix this on the next version that should come any time soon.

In the mean time in your code, simply pick one of the @Indexed subclasses of BaseClass and it should do what you want.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: polymorphic query builder
PostPosted: Thu Mar 03, 2011 12:44 pm 
Newbie

Joined: Thu Jul 19, 2007 11:21 am
Posts: 12
thanks for your reply. Yes, I meant to query on BaseClass fields indeed.

And yes, i already used approximately the same workaround.

Would be nice to have this extra feature though.

I am not too familiar with github but i have seen there's a plugin for my ide (idea), will check it out and post an unit test.

..and by the way, thanks for this great tool, i am soo pleased i've chosen it, like it each day so to speak.
--val


Top
 Profile  
 
 Post subject: Re: polymorphic query builder
PostPosted: Thu Mar 03, 2011 2:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Thanks :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: polymorphic query builder
PostPosted: Wed Nov 14, 2012 4:15 am 
Newbie

Joined: Tue Jul 19, 2011 2:16 pm
Posts: 19
Hi,

I have the same needs. I've already written a post here : https://forum.hibernate.org/viewtopic.php?f=9&t=1024718&p=2466423#p2466423.
sanne.grinovero talk to me about this post.

Today, do you have any solution to resolve this problem ?


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