-->
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: count() function
PostPosted: Thu May 22, 2014 9:20 am 
Newbie

Joined: Mon Feb 22, 2010 2:07 pm
Posts: 8
I am using ogm with mongodb on Glassfish v4.0.1.

Code:
@Entity
@Table(name = "blog_entry")
@NamedQueries({
        @NamedQuery(name = "blog_entry_list", query = "select be from BlogEntry be order by be.created"),
        @NamedQuery(name = "blog_entry_count", query = "select count(be) from BlogEntry be"),
})
public class BlogEntry extends AbstractEntity {
....
}


Code:
@Stateless
public class BlogEntryDaoBean extends AbstractDaoBean<BlogEntry> implements
      BlogEntryDao {
...

@Override
    public Long count() {
        Object result =  getEntityManager().createNamedQuery("blog_entry_count").getSingleResult();
        return (Long) result;
   }
}


when the blog_entry_count query is exequted, the result is of BlogEntry type. I would expect it to be a number in this case. Does ogm supports aggregate functions and count() in particular in HQL? Unfortunately I have not found any notion in the documentation. Thank you.
---------------------------
hibernate-ogm 4.1.0.Beta2, mongodb driver 2.11.3


Top
 Profile  
 
 Post subject: Re: count() function
PostPosted: Thu May 22, 2014 7:48 pm 
Newbie

Joined: Mon Feb 22, 2010 2:07 pm
Posts: 8
It appeared I was reading the documentation for version 3 and in the documentation for v4.1(http://docs.jboss.org/hibernate/ogm/4.1/reference/en-US/html_single/) it is stated there is no support for the aggregation functions

Quote:
no join, aggregation, or other relational operations are implied


I would still like to ask if any support for at least count() function is planned? Thank you


Top
 Profile  
 
 Post subject: Re: count() function
PostPosted: Fri May 23, 2014 2:54 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

We don't yet support any JP-QL/HQL functions when executing queries on MongoDB. I think it's a common requirement in applications where one wants to page through a result set, so I've created https://hibernate.atlassian.net/browse/OGM-534. Maybe you would like to help out with implementing this?

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: count() function
PostPosted: Fri May 23, 2014 3:08 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Btw. I'm planning to look into providing more powerful means of native queries for MongoDB (see https://hibernate.atlassian.net/browse/OGM-513; Currently only find() operations are possible). This would allow you to get the count like so:

Code:
@NamedNativeQuery(name = "blog_entry_count", query = "db.runCommand( { count: 'orders' } )"


Regarding the docs, the currently supported JP-QL constructs are listed in the reference guide here: https://docs.jboss.org/hibernate/ogm/4.1/reference/en-US/html_single/#ogm-mongodb-queries

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: count() function
PostPosted: Fri May 23, 2014 8:48 am 
Newbie

Joined: Mon Feb 22, 2010 2:07 pm
Posts: 8
Gunnar, thank you for the answer.
Quote:
Maybe you would like to help out with implementing this?


Maybe I can try. I have checked out the source code and debugged it a little bit just to see how it works internally. Cannot say I already figured out the way to go it would take some time.. I have never contributed for any open source products, so if can give little inside about the process and/or give a link to a process description I would really appreciate it. Actually any help with understanding how it works would be great.

Pavel


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.