Hi Baro,
I've looked into the issue you are having and I've found several things that needs to be changed in the project to make it work:
1) Move hibernate.cfg.xml and hibernate-contact.hbm.xml to src/main/resources/
2) I've changed hibernate.cfg.xml (I've removed mongodb port and host because I've used the default ones)
Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="hibernate.ogm.datastore.provider">MONGODB</property>
<property name="hibernate.ogm.mongodb.database">rcfdb</property>
<property name="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform</property>
<mapping resource="hibernate-contact.hbm.xml" />
</session-factory>
</hibernate-configuration>
3) Change the generator part of the hibernate-contact.hbm.xml to:
Code:
<id column="id" type="integer">
<generator class="org.hibernate.ogm.id.impl.OgmIdentityGenerator" />
</id>
This is probably a bug in OGM, what you did should have worked. I'm investigating it.
4) As for the dependencies on the classpath I've downloaded the Hibernate OGM distribution Beta1 and Beta2 from sourceforge. These are the links:
- http://sourceforge.net/projects/hibernate/files/hibernate-ogm/4.0.0.Beta1/hibernate-ogm-4.0.0.Beta1-dist.zip/download
- http://sourceforge.net/projects/hibernate/files/hibernate-ogm/4.0.0.Beta2/hibernate-ogm-4.0.0.Beta2-dist.zip/download
As dependencies, in the Beta2 distribution archive you need the content of the folders called "dist/lib/required", "dist/lib/provided" and "dist/lib/hibernate-ogm-core-4.0.0.Beta2.jar".
In Beta1 distribution package you need the content of the folder dist/lib/mongodb
You also need http://repo1.maven.org/maven2/org/jboss/jbossts/jbossjta/4.16.4.Final/jbossjta-4.16.4.Final.jar
Here the list of dependencies that you need:
antlr-2.7.7.jar
antlr-3.4.1-preview-jbossorg-0.jar
antlr-runtime-3.4.1-preview-jbossorg-0.jar
avro-1.6.3.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.9.Final.jar
hibernate-entitymanager-4.1.9.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate-jpql-parser-1.0.0.Alpha1.jar
hibernate-ogm-core-4.0.0.Beta2.jar
hibernate-ogm-mongodb-4.0.0.Beta1.jar
hibernate-search-engine-4.2.0.CR1.jar
hibernate-search-orm-4.2.0.CR1.jar
jackson-core-asl-1.8.8.jar
jackson-mapper-asl-1.8.8.jar
javassist-3.17.1-GA.jar
jboss-logging-3.1.1.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
jbossjta-4.16.4.Final.jar
jgroups-3.2.5.Final.jar
lucene-core-3.6.2.jar
lucene-facet-3.6.2.jar
mongo-java-driver-2.8.0.jar
paranamer-2.3.jar
slf4j-api-1.6.1.jar
snappy-java-1.0.4.1.jar
ST4-4.0.4.jar
staxmapper-1.1.0.Final.jar
stringtemplate-3.2.1.jar
5) I've changed the App in this way:
Code:
public static void main(String[] args) {
Configuration configuration = new OgmConfiguration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings( configuration.getProperties() ).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory( serviceRegistry );
Session session = sessionFactory.openSession();
session.beginTransaction();
System.out.println( "Populating the database..." );
Contact cnt = new Contact();
cnt.setFirstname( "Blabla" );
cnt.setLastname( "Blabla" );
cnt.setEmail( "blabla" );
session.save( cnt );
session.getTransaction().commit();
System.out.println( "Done... :)" );
}
Hopefully this should solve all the issues.