-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate integration with MongoDB
PostPosted: Mon Mar 11, 2013 5:37 am 
Newbie

Joined: Fri Mar 08, 2013 8:50 am
Posts: 2
I was actually trying to use hibernate ogm for mongodb using the following code.

Code:
import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transaction.*;
import org.hibernate.cfg.*;
import org.hibernate.ogm.datastore.mongodb.Environment;
import org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider;
import org.hibernate.service.*;
import org.junit.Test;
import org.tapas.dto.UserDetails;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;

public class UserProfile {
   public static void main(String[] args) throws IOException{
      String host1 = "127.0.0.1";
      Map<String, Object> cfg = new HashMap<String, Object>();
      cfg.put( Environment.MONGODB_HOST, host1 );
      cfg.put( Environment.MONGODB_PORT, "27017");
      cfg.put( Environment.MONGODB_DATABASE, "test" );
      MongoDBDatastoreProvider provider = new MongoDBDatastoreProvider();
      provider.configure( cfg );
      provider.start();   
      DB database = provider.getDatabase();
      DBCollection collection = database.getCollection( "first" );
      BasicDBObject water = new BasicDBObject();
      water.put( "_id", "1234" );
      water.put( "name", "Water" );
      water.put( "volume", "1L" );
      collection.insert( water );
      System.out.println("yes");
   }      
}


But when am trying to run this, am getting an exception saying that:

Exception in thread "main" java.lang.NoClassDefFoundError: com/mongodb/MongoClientOptions$Builder
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:133)
at org.tapas.hibernate.UserProfile.main(UserProfile.java:82)
Caused by: java.lang.ClassNotFoundException: com.mongodb.MongoClientOptions$Builder
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 2 more

Can someone please help me out...


Top
 Profile  
 
 Post subject: Re: Hibernate integration with MongoDB
PostPosted: Tue Apr 02, 2013 9:04 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
do you have version 2.10.1 of the mongo-java-driver on the classpath?


Top
 Profile  
 
 Post subject: Re: Hibernate integration with MongoDB
PostPosted: Tue Apr 02, 2013 9:11 am 
Newbie

Joined: Fri Mar 08, 2013 8:50 am
Posts: 2
yes. am using mongo-java-driver-2.10.1.jar only.


Top
 Profile  
 
 Post subject: Re: Hibernate integration with MongoDB
PostPosted: Thu Apr 04, 2013 7:40 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
com.mongodb.MongoClientOptions.Builder class should exists in the mongo-java-driver since 2.10, a class not found error means that your application is not finding the JAR on the class path. I think there is an error in the configuration of your application and the JAR is probably not included among the dependencies.

If you give some more detail about the project maybe I can help.


Top
 Profile  
 
 Post subject: Re: Hibernate integration with MongoDB
PostPosted: Mon Jul 22, 2013 3:30 am 
Newbie

Joined: Mon Jul 22, 2013 3:20 am
Posts: 1
it is really nice post i like this info i appreciate this post keep it up.........

_________________
Michael


Top
 Profile  
 
 Post subject: Re: Hibernate integration with MongoDB
PostPosted: Mon Apr 14, 2014 2:59 am 
Newbie

Joined: Mon Apr 14, 2014 2:56 am
Posts: 1
It seems like there is an error in the configuration of your application that you have shared here and the JAR is probably not included among the dependencies which are producing this error. I am not able to find the error happened here. It is better you consult with any good programmer what is the error and rewrite the code.



Thanks
JANE


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