-->
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.  [ 9 posts ] 
Author Message
 Post subject: configuration file is not getting detected-MongoDB
PostPosted: Wed Aug 07, 2013 7:22 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
I want to use HibernateOGM to interact with MongoDB. I have an cfg.xml file like this:

Code:
<hibernate-configuration>
  <session-factory>
      <property name="hibernate.transaction.factory_class">org.transaction.JDBCTransactionFactory</property>
      <property name="hibernate.current_session_context_class">thread</property>
      <property name="hibernate.ogm.datastore.provider">mongodb</property>
      <property name="hibernate.ogm.datastore.grid_dialect">org.hibernate.ogm.dialect.MongoDBDialect</property>
      <property name="hibernate.ogm.mongodb.database">rcfdb</property>
      <property name="hibernate.ogm.mongodb.host">127.0.0.1</property>
      <property name="hibernate.ogm.mongodb.port">27017</property>
      <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
      <mapping resource="hibernate-contact.hbm.xml"/>   
  </session-factory>
</hibernate-configuration>


I have also wrote my POJO class, and in the main class I want to populate the database in the mongodb with this code, but I am not able to do this job and I get these line of Infos, how can I solve that:

Code:
Session session=null;
            OgmConfiguration cfgogm=new OgmConfiguration();
            SessionFactory sessionfactory= cfgogm.buildSessionFactory();
            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... :)");


I have no output with this code, and also no exceptions

INFO Lines:
Image


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Thu Aug 08, 2013 5:45 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
the properties look good (although you don't need to specify the dialect). Maybe there is something wrong in the classpath, could you give me more details about the project?

Davide


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Mon Aug 12, 2013 6:40 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
davided80 wrote:
Hi,
the properties look good (although you don't need to specify the dialect). Maybe there is something wrong in the classpath, could you give me more details about the project?


Hi Davide,

My my hibernate.cfg.xml and hbm.xml are located in src/main/resources. For testing, I have put these both file into src/main/resources/META-INFO, but the errors remain. my hbm.xml file looks like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="Untersuchungsraum.Contact" table="District">
  <id  column="id" type="integer" >
      <generator class="native">
      </generator>
  </id>
  <property name="firstname" type="string">
      <column name="Firstname"></column>
  </property>

  <property name="lastname" type="string">
      <column  name="lastname"></column>
  </property>

  <property name="email" type="string">
      <column name="email"></column>
  </property>
  </class>
  </hibernate-mapping>


and this is my contact class:
Code:
public class Contact {
    private String email;
    private String firstname;
    private String lastname;

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the fax
     */
   

    /**
     * @return the firstname
     */
    public String getFirstname() {
        return firstname;
    }

    /**
     * @param firstname the firstname to set
     */
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    /**
     * @return the lastname
     */
    public String getLastname() {
        return lastname;
    }

    /**
     * @param lastname the lastname to set
     */
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    /**
     * @return the gender
     */
   

   
}


whith this code I have the first Output Populating the database... and not the second oneDone... :)


Image

and generally my project looks like this:

Image


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Wed Aug 14, 2013 9:52 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi Baro,
it seems I was wrong about the properties, could you try to remove these:
hibernate.connection.provider_class
hibernate.transaction.factory_class


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Wed Aug 14, 2013 11:11 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
Hi
Somehow I have asked a complicated question. I did what you said. some problems are solved but now I have new problems:

I have changed my hibernate.cfg.xml to:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration> 
  <session-factory>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.ogm.datastore.provider">MongoDB</property>
    <property name="hibernate.ogm.datastore.grid_dialect">org.hibernate.ogm.dialect.mongodb.MongoDBDialect</property>
    <property name="hibernate.ogm.mongodb.database">rcfdb</property>
    <property name="hibernate.ogm.mongodb.host">127.0.0.1</property>
    <property name="hibernate.ogm.mongodb.port">27017</property>
    <mapping resource="hibernate-contact.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


and now I have these exceptions:

Scanning for projects...

------------------------------------------------------------------------
Building HibernateOGM_MongoDB 1.0-SNAPSHOT
------------------------------------------------------------------------

[resources:resources]
[debug] execute contextualize
Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
Copying 2 resources

[compiler:compile]
Nothing to compile - all classes are up to date

[exec:exec]
Aug 14, 2013 5:12:05 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Aug 14, 2013 5:12:05 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.9.Final}
Aug 14, 2013 5:12:05 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 14, 2013 5:12:05 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 14, 2013 5:12:05 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
Aug 14, 2013 5:12:05 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: hibernate.cfg.xml
Aug 14, 2013 5:12:05 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Aug 14, 2013 5:12:05 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: hibernate-contact.hbm.xml
Aug 14, 2013 5:12:05 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Aug 14, 2013 5:12:05 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Aug 14, 2013 5:12:06 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.ogm.dialect.NoopDialect
Aug 14, 2013 5:12:06 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
Aug 14, 2013 5:12:06 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Aug 14, 2013 5:12:06 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Aug 14, 2013 5:12:06 PM org.hibernate.ogm.cfg.impl.Version <clinit>
INFO: OGM000001: Hibernate OGM 4.0.0.Beta1
Exception in thread "main" org.hibernate.MappingException: Could not get constructor for org.hibernate.ogm.persister.OgmEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:185)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:383)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
at hogm.hibernateogm_mongodb.App.main(App.java:30)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.ogm.datastore.spi.DatastoreProvider]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.ogm.datastore.impl.DatastoreServicesImpl.configure(DatastoreServicesImpl.java:53)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.ogm.persister.OgmEntityPersister.<init>(OgmEntityPersister.java:125)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
... 4 more
Caused by: org.hibernate.HibernateException: OGM000008: DatastoreManager class [MongoDB] cannot be found in classpath try with: [MAP, INFINISPAN, EHCACHE, MONGODB]
at org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator.buildServiceInstance(DatastoreProviderInitiator.java:64)
at org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator.buildServiceInstance(DatastoreProviderInitiator.java:40)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:37)
at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)
... 16 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.411s
Finished at: Wed Aug 14 17:12:06 PDT 2013
Final Memory: 4M/15M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project HibernateOGM_MongoDB: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


How can I solve these wxceptions?


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Mon Aug 19, 2013 1:12 pm 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
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.


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Mon Aug 19, 2013 1:25 pm 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
I've pushed the example that I've tested on https://github.com/DavideD/ogm-mongodb-example

It is a maven project though since I didn't want to push all the libraries.


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Tue Aug 20, 2013 10:31 am 
Beginner
Beginner

Joined: Thu Jul 11, 2013 7:58 am
Posts: 22
Hi thank you so much for your detailed answer :)

I have solved my problem in another way:

I had:

hibernate-ogm-core-4.0.0.Beta2.jar
hibernate-ogm-mongodb-4.0.0.Beta1.jar


Someone sqid me that these two files with different version don't work correctly. then I have used:

hibernate-ogm-core-4.0.0.SNAPSHOP.jar
hibernate-ogm-mongodb-4.0.0.SNAPSHOT.jar


As yoou can see, both of them should be SNAPSHOT

after these two small changes, my programm works without any bugs

as I understand that was a bug from hibernate-ogm-mongodb-4.0.0.Beta1.jar


Top
 Profile  
 
 Post subject: Re: configuration file is not getting detected-MongoDB
PostPosted: Wed Aug 21, 2013 5:03 am 
Hibernate Team
Hibernate Team

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


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