-->
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.  [ 10 posts ] 
Author Message
 Post subject: Using MonngoDB with hibernate OGM
PostPosted: Mon Jun 25, 2012 7:12 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
I am new to Hibernate OGM just started to play around. I got the source file from
https://github.com/hibernate/hibernate-ogm
Using maven I am able to build the source also.
Now I want to use MongoDB with Hibernate OGM so I wrote a simple application. My persistence.xml file looks like :
Code:
<persistence-unit name="org.hibernate.ogm.tutorial.jpa" transaction-type="JTA">
      <!-- Use Hibernate OGM provider: configuration will be transparent -->
      <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
      <properties>
         <property name="hibernate.transaction.manager_lookup_class"
                      value="org.hibernate.transaction.JBossTSStandaloneTransactionManagerLookup"/>
       
         <property name="jboss.as.jpa.providerModule" value="org.hibernate:ogm"/>
        <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
      <property name="hibernate.ogm.mongodb.database" value="booking"/>
      <property name="hibernate.ogm.mongodb.host" value="localhost"/>
      <property name="hibernate.search.default.directory_provider" value="filesystem"/>
       
        <property name="hibernate.dialect" value="org.hibernate.ogm.dialect.mongodb.MongoDBDialect"/>
       
        </properties>
   </persistence-unit>


Now in the Runner class I am trying to create EMF . I am getting following exception :
Code:
SEVERE: Could not find datasource: ---PlaceHolderDSForOGM---
Throwable occurred: javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {} [Root exception is java.lang.NullPointerException]


When I looked at the method enforceOgmConfig() in class org.hibernate.ogm.jpa.HibernateOgmPersistence I found that dialect and datasource is set blindly here. So my configuration to pick MongoDb as database-server and the specified database name is not woking.

I am not able to find what I am missing here ? Any thoughts, suggestion will be helpful .

Thanks,
Ganesh


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 4:07 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Ganesh,
that exception happens when it's being started with the wrong version of Hibernate ORM.

Are you starting it in a container? Since you set the property jboss.as.jpa.providerModule I'm guessing that you started in on JBoss7 ?
For that to work, you have to install a custom ogm module in the application server; you can have a look at this example application as mentioned on this blogpost:

http://in.relation.to/Bloggers/UpdatedO ... inkExample

If you checkout that source, you'll see I had to include some jars in the application directly to package the custom module. We still need to make that easier in upcoming versions of JBoss.

Please let me know how your experiments go, and if you need more help.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 5:45 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
I am not using the application in AS env. As I could not get any documentation about the properties I was just playing around so I put jboss.as.jpa.providerModule property. I have written a standalone application.

Can you please point me to some documentation which can explain me how I can use OGM with MongoDB ?

Thanks,
Ganesh


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 6:04 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I'm afraid the docs published on the website are a bit outdated, specifically they don't mention MongoDB yet.

This is a copy/paste from the documentation preview relative to MongoDB:

Quote:
To use Hibernate OGM with MongoDB there are four properties to configure:

hibernate.ogm.datastore.provider to set to org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider
hibernate.ogm.mongodb.host which is the hostname of the mongodb instance. The default value is 127.0.0.1
hibernate.ogm.mongodb.port which is the port used by the mongodb instance. The default value is 27017
hibernate.ogm.mongodb.database which is the database to connect to
To enable the safe mode (which means WriteConcern.SAFE for all operations) you have to use hibernate.ogm.mongodb.safe and set it to true


To build the documentation yourself (it's in docbook format in the sources, so you already have it):
Code:
cd hibernate-ogm-documentation/manual
mvn org.jboss.maven.plugins:maven-jdocbook-plugin:2.3.5:translate org.jboss.maven.plugins:maven-jdocbook-plugin:2.3.5:resources org.jboss.maven.plugins:maven-jdocbook-plugin:2.3.5:generate
firefox ./target/docbook/publish/en-US/html_single/index.html


So assuming you are using the default port, your persistence.xml looks like correct.
As mentioned, the exception you have shown means you are using the wrong version of Hibernate core. You must use Hibernate-core v. 4.1.4 , as indicated in the root pom.xml

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 6:20 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
I have all those properties set in the persistence.xml file.

when I used hibernate4.1.4.final.jar I found java.lang.NoClassDefFoundError: org.hibernate.util.xml.Origin exception.
I am using hibernate-ogm-mongodb-4.0.0-SNAPSHOT.jar and hibernate-ogm-core-4.0.0-SNAPSHOT.jar.

So let me know the compatible version of hibernate-core and hibernate-entitymanager.
Thanks,
Ganesh


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 6:25 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
org.hibernate.util.xml.Origin is in the hibernate-core-4.1.4.Final.jar .. so either your downloaded jar is corrupted, or something is wrong with your classpath?

Quote:
So let me know the compatible version of hibernate-core and hibernate-entitymanager.

It's 4.1.4.Final for all Hibernate Core and Entitymanager jars.

You could run:
Code:
mvn dependency:tree

to have all details reported by Maven itself.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 6:52 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
A small correction I think org.hibernate.util.xml.Origin class is changed to org.hibernate.internal.jaxb.Origin in Hibernate 4.1.4.

Anyway I downloaded the complete package of Hibernate 4.1.4 jars , removed old jars and added new jars to the classpath. Now that exception went off. Now I am facing some problem with my mongoDb server. I will fix that and will get some hands on.

I will get back to you if I get some problem or will share the experience if I am able to successfully run -:)

Thanks Much,
Ganesh


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Wed Jun 27, 2012 7:11 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
So finally I am able to run a small program .

Thanks,
Ganesh


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Mon Jan 14, 2013 2:50 am 
Newbie

Joined: Mon Jan 14, 2013 2:43 am
Posts: 1
Hi,

I have been working with a simple app to persist data into MongoDb using Hibernate OGM. i am getting an exception:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named HibMongoPU: Provider named org.hibernate.ejb.HibernatePersistence threw unexpected exception at create EntityManagerFactory:
java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: org/hibernate/util/xml/Origin


I assume this is due to the jar version mismatch. Kindly let me know what jars i need to add and which version. i have created the app as a web application and using tomcat webserver.


Top
 Profile  
 
 Post subject: Re: Using MonngoDB with hibernate OGM
PostPosted: Mon Jan 14, 2013 3:51 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
What version of Hibernate OGM are you using?

The quickest way to find out which version of the other dependencies you need it to either inspect the Maven pom.xml in the sources of the project at the version you're experimenting with, or to download the distribution from sourceforge and take the jars we include with the archive:

https://sourceforge.net/projects/hibernate/files/hibernate-ogm/

_________________
Sanne
http://in.relation.to/


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