-->
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: Adding persistance.xml for hibernate OGM?
PostPosted: Thu Jul 11, 2013 8:25 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
I would like to working with hibernate OGM. As I read here I should have a persistance.xml file, with that I am able to configure this persistance.xml for using hibernate OGM.

As you can see in the image. If I want to add JPA, the wizard needs Database connection, but I cant see the MongoDB but I dont want to have this persistance for another dbs.
Image

My question is now:

    How can I add persistance.xml for MongoDB? or should
    Is it correct if I add Persistance for JDBC and then use it for MongodB
Sorry Im relative new to java and MongoDB :( could please explain me in detail


Top
 Profile  
 
 Post subject: Re: Adding persistance.xml for hibernate OGM?
PostPosted: Fri Jul 12, 2013 8:10 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi Baro,

to use OGM with MongoDB you need to add a persistence.xml to your project that looks something like this:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="primary">
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>

    <properties>
      <property name="hibernate.ogm.datastore.provider" value="mongodb"/>
      <property name="hibernate.ogm.mongodb.host" value="127.0.0.1"/>
      <property name="hibernate.ogm.mongodb.port" value="27018"/>
      <property name="hibernate.ogm.mongodb.database" value="database_name"/>
    </properties>
  </persistence-unit>
</persistence>


The property "hibernate.ogm.datastore.provider" needs to be set to the value "mongodb".

This example is using some default configuration the are valid if your mongodb instance is on localhost and it is using the default port.
You have to change "database_name" with the name of the database you want to connect to.

I'm don't know how you can set up your IDE wizard to generate this kind of file but if you want to have MongoDB in the dropdow menu I would guess you need to download the MongoDB JDBC driver and configure a database connection.

I hope this can help, if you have other questions don't hesitate to ask.


Top
 Profile  
 
 Post subject: Re: Adding persistance.xml for hibernate OGM?
PostPosted: Fri Jul 19, 2013 5:51 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
Hi,

thank you for your help. I try to finde a very simple example using hibernate OGM and MongoDB without using Maven, but I had no success. Could you please post an example or offer a website that I learn more about it? thanks :)


Top
 Profile  
 
 Post subject: Re: Adding persistance.xml for hibernate OGM?
PostPosted: Mon Jul 22, 2013 5:56 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Which version of OGM are you using?


Top
 Profile  
 
 Post subject: Re: Adding persistance.xml for hibernate OGM?
PostPosted: Mon Jul 22, 2013 6:00 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
Hi,

I am using hibernate-ogm-mongodb-4.0.0.Beta1.jar


Top
 Profile  
 
 Post subject: Re: Adding persistance.xml for hibernate OGM?
PostPosted: Tue Jul 23, 2013 5:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
A distribution package with all the dependencies can be found on SourceForge: http://sourceforge.net/projects/hibernate/files/hibernate-ogm/

In 4.0.0.Beta1 you will find a dist folder that should contain all the dependencies.

I would also suggest to try a most recent version but in the Beta2 dist archive the mongodb dependencies are missing so you would need to add:
staxmapper-1.1.0.Final.jar
mongo-java-driver-2.10.1.jar

You should also add:
hibernate-ogm-mongodb-4.0.0.Beta2.jar

the problem is that I wasn't able to find it on a remote maven repository, I think that it has been released with the name hibernate-ogm-mongodb-4.0.0-SNAPSHOT

If you are familiar with maven and git you can also try the latest version on the repository.

Let me know if this has helped and don't hesitate to ask if you have more questions.


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.