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...