-->
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.  [ 7 posts ] 
Author Message
 Post subject: NamedQueries are not supported
PostPosted: Mon Aug 25, 2014 9:47 am 
Newbie

Joined: Mon Aug 25, 2014 9:42 am
Posts: 10
Good day guys, I hope you can help me. I wanted to start using named queries with OGM, however when I run them they always return empty list. I have a setup of the SPRING and HIBERNATE OGM and MONGODB. Before I dig in and post more data here, can u just confirm that name queries and query criteria builder are supported with the most recent version of OGM. Thank you. Great product by the way!


Top
 Profile  
 
 Post subject: Re: NamedQueries are not supported
PostPosted: Tue Aug 26, 2014 11:23 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
Named queries are supported:
- NamedQuery: https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/backendtck/queries/SimpleQueriesTest.java#L397
- NamedNativeQuery: https://github.com/hibernate/hibernate-ogm/blob/a9eefdc76ed7d82c86e482790a80a9147965b9ba/mongodb/src/test/java/org/hibernate/ogm/datastore/mongodb/test/query/nativequery/MongoDBSessionNativeQueryTest.java#L162

Criterias aren't: https://hibernate.atlassian.net/browse/OGM-23

Thanks,
Davide


Top
 Profile  
 
 Post subject: Re: NamedQueries are not supported
PostPosted: Tue Aug 26, 2014 1:36 pm 
Newbie

Joined: Mon Aug 25, 2014 9:42 am
Posts: 10
This is great, thank you for your reply, so I moved forward and now getting an exception:

javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of com.test.entity.model.user.User.id
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:458)
at com.test.dao.user.UserDao.getUsers(UserDao.java:63)


Here is my User entity:

Code:
@Entity
@Indexed
@NamedQueries({
   @NamedQuery(name = "user.getUsers", query = "select u from User u")
})
@Table(name = "user")
public class User {

   private static final transient Logger LOG = LoggerFactory.getLogger(User.class);

   
   @Id
   @GeneratedValue(generator = "uuid")
   @GenericGenerator(name = "uuid", strategy = "uuid2")
     public String id;

   @Column(name = "first_name", nullable = false)
   @Field(analyze = Analyze.NO)
   private String firstName;

   @Field(analyze = Analyze.NO)
   @Column(name = "last_name", nullable = false)
   private String lastName;

   public User() {
   }
   
   public int compareTo(User o) {
      return 0;
   }
   

   public String getId() {
          return id;
     }

     public void setId(String id) {
        this.id = id;
     }
   
   public String getFirstName() {
      return firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public String getLastName() {
      return lastName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }



Here is my UserDao

Code:
@Named
public class UserDao {
   
   protected EntityManagerFactory emf = Persistence.createEntityManagerFactory("mongo-hibernate");

   protected EntityManager entityManager = emf.createEntityManager();
   
   public List<User> getUsers() {
      TypedQuery<User> namedQuery = entityManager.createNamedQuery("user.getUsers", User.class);
      
          return namedQuery.getResultList();
     }   


}


Top
 Profile  
 
 Post subject: Re: NamedQueries are not supported
PostPosted: Tue Aug 26, 2014 4:31 pm 
Newbie

Joined: Mon Aug 25, 2014 9:42 am
Posts: 10
I think I figured it out. I was using also mongoDbTemplate form the spring framework to insert data while testing hibernate. and appears that spring inserted ID as ObjectId, and hibernate was reading it as a STRING.

Also going forward I had issues with the transactions. Everywhere it is mentioned that factory must be this.

Code:
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory​"/>


However it appears to be wrong with the most recent version, I think u guys moved it here:

Code:
<property name="hibernate.transaction.factory_class" value="org.hibernate.ogm.transaction.impl.JTATransactionManagerTransactionFactory"/>


Also , previously with ORM I was using annotation :
Code:
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)


is there anything similar to this with OGM ? So I dont have to have the lines like

Code:
Session session = entityManager.unwrap(Session.class);         
Transaction tx = session.getTransaction(); 
tx.begin();
.....


Top
 Profile  
 
 Post subject: Re: NamedQueries are not supported
PostPosted: Wed Aug 27, 2014 6:29 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Quote:
However it appears to be wrong with the most recent version, I think u guys moved it here
Code:
Code:
<property name="hibernate.transaction.factory_class" value="org.hibernate.ogm.transaction.impl.JTATransactionManagerTransactionFactory"/>


You're right, thanks for spotting this.

I'm not familiar with Spring but the annotation looks similar to javax.persistence.Transactional.
Therefore, if you have a JEE container, you can create something similar to what we did in our integration test: https://github.com/hibernate/hibernate-ogm/blob/master/integrationtest/testcase/src/test/java/org/hibernate/ogm/test/integration/jboss/controller/MemberRegistration.java

Since OGM is using the same API of ORM I would have expected this to work though. Could provide a testcase?


Top
 Profile  
 
 Post subject: Re: NamedQueries are not supported
PostPosted: Fri Sep 05, 2014 11:58 am 
Newbie

Joined: Mon Aug 25, 2014 9:42 am
Posts: 10
No I am trying to run named query with join or join fetch and getting exception that it is not supported yet. Can you please confirm that ? that I can do only simple select queries or I am doing something wrong. thank you!


Top
 Profile  
 
 Post subject: Re: NamedQueries are not supported
PostPosted: Mon Sep 08, 2014 4:22 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
OGM does not support join queries at the moment.

From the documentation (http://docs.jboss.org/hibernate/ogm/4.1/reference/en-US/html/ogm-query.html):

Quote:
Note that the following preconditions must be met:

- no join, aggregation, or other relational operations are implied


In the MongoDB section:

Quote:
Hibernate OGM is a work in progress, so only a sub-set of JP-QL constructs is available when using the JP-QL query support. This includes:

- simple comparisons using "<", "⇐", "=", ">=" and ">"
- IS NULL and IS NOT NULL
- the boolean operators AND, OR, NOT
- LIKE, IN and BETWEEN
- ORDER BY

Queries using these constructs will be transformed into equivalent native MongoDB queries.


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