-->
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.  [ 9 posts ] 
Author Message
 Post subject: find all entities of a type
PostPosted: Thu Dec 15, 2011 11:19 am 
Beginner
Beginner

Joined: Thu Sep 01, 2005 10:09 am
Posts: 39
HI, I just made a simple try with OGM a few days ago. I wonder if I could do something like "select from table" without any restrictions. If I had funtionality like this, I could get a working prototype, as almost all my other queries run through search/lucene already.


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Sun Jan 01, 2012 10:50 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
no even such a simple query is not currently supported via JPQL; still you can use a Hibernate Search query to do the same: just have it target a specific type and use a MatchAllDocsQuery:

Code:
Query luceneQuery =  new MatchAllDocsQuery();
FullTextQuery query = s.createFullTextQuery( luceneQuery, MyEntity.class );


Sorry for the late reply, something was wrong with notifications from the new forum section.
I'd expect indeed that this should be enough for some use cases, let us know!

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Fri Sep 21, 2012 5:13 am 
Newbie

Joined: Fri Sep 21, 2012 4:15 am
Posts: 4
Hi,
I have the same need as hyperion.
I try to execute the MatchAllDocsQuery lucene query but the result list is always empty (although there are objects present).
However, I can retrieves my objets by primary key...

I do womething wrong ?

Code:
final FullTextSession fullTextSession = Search.getFullTextSession( session );
Query luceneQuery =  new MatchAllDocsQuery();
final FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, MyEntity.class );
List<T> result = (List<T>) fullTextQuery.list();


PS: I use the 4.0.0-SNAPSHOT version of Hibernate OGM.


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Fri Sep 21, 2012 6:02 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
how are you building the Lucene indexes? There is currently and unresolved problem with the MassIndexer from Hibernate Search, it won't work correctly in combination with Hibernate OGM:

https://hibernate.onjira.com/browse/OGM-228

Are you using the Infinispan grid dialect?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Fri Sep 21, 2012 9:04 am 
Newbie

Joined: Fri Sep 21, 2012 4:15 am
Posts: 4
Hi and thanks for the quick reply.

I did not see this bug. I'm using Hibernate OGM out of the box now for test (I did just minimal configuration).
How to set the grid dialect ?

An other question: I also plan to use Hibernate OGM with EhCache. Does the actual 4.00-SNAPSHOT is quite stable for EhCache and does it works with lucene queries ?


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Fri Sep 21, 2012 10:41 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Lucene queries are independent from the grid dialect used, so you can use it with Ehcache as with anything else.

If you need multiple nodes, sharing the same index across nodes is easier of you use Infinispan but you can get a similar setup with any other backend.

The grid dialect is a configuration option to override the default grid connectivity; see the readme.me file about how to build the documentation.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Fri Sep 21, 2012 11:12 am 
Newbie

Joined: Fri Sep 21, 2012 4:15 am
Posts: 4
I override the property by setting Inifinispan grid dialect:

<property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.dialect.infinispan.InfinispanDialect" />

But my MatchAllDocsQuery query continue to returns empty result. What's wrong ?


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Fri Sep 21, 2012 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Are you storing something? Did you mark your entities for indexing?

If you can provide a test that I could execute I'll have a look.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: find all entities of a type
PostPosted: Mon Sep 24, 2012 5:41 am 
Newbie

Joined: Fri Sep 21, 2012 4:15 am
Posts: 4
Thanks for your help.

I am storing one entity that I can retrieve successfully by a EntityManager.find() call.

My test case is:

Code:
@Entity
@Indexed
public class A {
   @Id
   @Column(name = "ID")
   @DocumentId
   private/* final */String id;
   
   @Column(name = "DESC")
   private String desc;
   
   public A(){}
   
   public A(String id, String desc){
      this.id = id;
      this.desc =  desc;
   }
}


Code:
public class TestCase {

public static void main(String[] args) throws Exception {
EntityManager em;
EntityManagerFactory f = Persistence.createEntityManagerFactory("MyTestCase");
A a = new A("id", "desc");

EntityManager em = f.createEntityManager();
EntityTransaction t = em.getTransaction();
t.begin();
em.persist(a);
t.commit();
em.close();

em = f.createEntityManager();
t = em.getTransaction();
t.begin();
A findItem= em.find(A.class, "id");
System.out.println("Item: " + findItem);
t.commit();
em.close();

em = f.createEntityManager();
Session session = (org.hibernate.Session)em.getDelegate();
final FullTextSession fullTextSession = Search.getFullTextSession( session );
final FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(new MatchAllDocsQuery(), A.class);
List<A> result = (List<A>) fullTextQuery.list();
System.out.println("Query result size: " + result.size());
}


Code:
<persistence-unit name="MyTestCase">
      <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
      <class>com.swingws.pav.core.impl.model.A</class>
      
      <properties>
      <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory" />
         <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />
         <property name="hibernate.ogm.datastore.provider" value="infinispan" />
         <property name="hibernate.ogm.datastore.grid_dialect" value="org.hibernate.ogm.dialect.infinispan.InfinispanDialect" />
         <property name="hibernate.search.default.directory_provider" value="filesystem" />
         <property name="hibernate.search.default.indexBase" value="lucene/indexes" />
         <property name="hibernate.search.Rules.directory_provider" value="ram" />
         <property name="hibernate.search.Actions.directory_provider" value="com.acme.hibernate.CustomDirectoryProvider" />
      </properties>
   </persistence-unit>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.