-->
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: Exception in update query
PostPosted: Wed Apr 13, 2016 9:04 am 
Newbie

Joined: Wed Apr 13, 2016 8:21 am
Posts: 7
Hii Team,
Iam trying to increment a field by using native query, it is throwing JSONParseException.

entityManager.getTransaction().begin();
Query desc = entityManager
.createNativeQuery("db.UserFactualContent.update({'TOKEN':'8gphgbceqqlih270b3993mian7'},{'$inc':{'clicks': 1}})");
System.out.println(desc.executeUpdate());
entityManager.getTransaction().commit();



INFO: OGM000001: Hibernate OGM 4.2.0.Final
com.mongodb.util.JSONParseException:
db.UserFactualContent.update({'TOKEN':'8gphgbceqqlih270b3993mian7'},{'$inc':{'clicks': 1}})
^
at com.mongodb.util.JSONParser.parse(JSON.java:208)
at com.mongodb.util.JSONParser.parse(JSON.java:155)
at com.mongodb.util.JSON.parse(JSON.java:93)
at com.mongodb.util.JSON.parse(JSON.java:74)
at org.hibernate.ogm.datastore.mongodb.query.parsing.nativequery.impl.MongoDBQueryDescriptorBuilder.build(MongoDBQueryDescriptorBuilder.java:48)
at org.hibernate.ogm.datastore.mongodb.MongoDBDialect.parseNativeQuery(MongoDBDialect.java:725)
at org.hibernate.ogm.datastore.mongodb.MongoDBDialect.parseNativeQuery(MongoDBDialect.java:128)
at org.hibernate.ogm.dialect.impl.ForwardingGridDialect.parseNativeQuery(ForwardingGridDialect.java:191)
at org.hibernate.ogm.query.impl.NativeNoSqlQueryInterpreter.getCustomQuery(NativeNoSqlQueryInterpreter.java:50)
at org.hibernate.ogm.query.impl.NativeNoSqlQueryInterpreter.createQueryPlan(NativeNoSqlQueryInterpreter.java:45)
at org.hibernate.engine.query.spi.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:226)
at org.hibernate.internal.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:305)
at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1338)
at org.hibernate.engine.spi.SessionDelegatorBaseImpl.executeNativeUpdate(SessionDelegatorBaseImpl.java:284)
at org.hibernate.ogm.query.impl.NoSQLQueryImpl.executeUpdate(NoSQLQueryImpl.java:402)
at org.hibernate.jpa.internal.QueryImpl.internalExecuteUpdate(QueryImpl.java:371)
at org.hibernate.jpa.spi.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:78)


Top
 Profile  
 
 Post subject: Re: Exception in update query
PostPosted: Wed Apr 13, 2016 12:14 pm 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
you need Hibernate OGM 5 CR1 for the support of native updates using the Mongo CLI syntax.

Cheers,
Davide


Top
 Profile  
 
 Post subject: Re: Exception in update query
PostPosted: Thu Apr 14, 2016 6:16 am 
Newbie

Joined: Wed Apr 13, 2016 8:21 am
Posts: 7
Hii,
after adding Hibernate OGM 5 CR1, iam getting multiple exceptions after adding the dependency jars by changing the versions...
org/hibernate/boot/registry/classloading/spi/ClassLoaderService
org/hibernate/metamodel/source/XsdException
org/hibernate/engine/jndi/JndiNameException
org/hibernate/resource/transaction/TransactionCoordinatorBuilder

Hibernate dependency jars that iam using are:


Code:
<dependency>
   <groupId>org.mongodb</groupId>
   <artifactId>mongo-java-driver</artifactId>
   <version>3.2.2</version>
</dependency>      
  <dependency>
   <groupId>org.hibernate.ogm</groupId>
   <artifactId>hibernate-ogm-mongodb</artifactId>
   <version>4.2.0.Final</version>
</dependency> 
<dependency>
   <groupId>org.hibernate.ogm</groupId>
   <artifactId>hibernate-ogm-core</artifactId>
   <version>5.0.0.CR1</version>
</dependency>
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>4.0.0.Alpha3</version>
</dependency>


the code is:
Code:
  entityManager.getTransaction().begin();
         Query desc = entityManager
               .createNativeQuery("db.UserFactualContent.update({'TOKEN':'8gphgbceqqlih270b3993mian7'},{'$inc':{'clicks': 1}})");
         System.out.println(desc.executeUpdate());
         entityManager.getTransaction().commit();




Regards,
Javed.


Top
 Profile  
 
 Post subject: Re: Exception in update query
PostPosted: Thu Apr 14, 2016 6:25 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
The versions of your dependencies don't match.

Please import the Hibernate OGM BOM into your dependencyManagement block as described in https://docs.jboss.org/hibernate/ogm/5. ... ingstarted and then add dependencies to the different OGM modules but also Hibernate ORM without any version. You'll get the versions from the BOM then.

Essentially, you need to use the same version of all Hibernate OGM modules, and OGM 5.0 is aligned with Hibernate ORM 5.0.

--Gunnar

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


Top
 Profile  
 
 Post subject: Re: Exception in update query
PostPosted: Thu Apr 14, 2016 7:42 am 
Newbie

Joined: Wed Apr 13, 2016 8:21 am
Posts: 7
Hi team,
The issue is resolved now, thanks a lot...

Regards,
Javed.


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.