-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mongo and MySQL co-existence
PostPosted: Fri Feb 21, 2014 2:56 am 
Newbie

Joined: Fri Feb 21, 2014 2:40 am
Posts: 2
I need to use both MySQL and MongoDB in my project. MySQL for structured data and MongoDB for unstructured.

I see that if I import the ogm classes for MongoDB, then MySQL sessionfactory creation has the below trace.

Feb 21, 2014 11:53:52 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
Feb 21, 2014 11:53:53 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Feb 21, 2014 11:53:53 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Feb 21, 2014 11:53:53 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Feb 21, 2014 11:53:53 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:988)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.locateServiceBinding(AbstractServiceRegistryImpl.java:114)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.locateServiceBinding(AbstractServiceRegistryImpl.java:109)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:124)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:36)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:41)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:41)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:41)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:41)

It seems that MySQL sessionfactory creation is using OGM classes. I'm able to create MySQL and MongoDB sessions separately (so the code is working if I comment out either one of MySQL or MongoDB related code).

Below is my code -

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.Session;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.ogm.cfg.OgmConfiguration;

public class Platform {

private static final SessionFactory mySQLSessionFactory = buildMySQLSessionFactory();
private static final SessionFactory mongoSessionFactory = buildMongoSessionFactory();


private static SessionFactory buildMySQLSessionFactory() {
Configuration configuration = new Configuration();
configuration.configure("mysql.cfg.xml");
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
org.hibernate.SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}

private static SessionFactory buildMongoSessionFactory() {
OgmConfiguration configuration=new OgmConfiguration();
configuration.configure("mongdb.cfg.xml");
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
org.hibernate.ogm.SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}

public static void shutdown() {
mySQLSessionFactory.close();
mongoSessionFactory.close();
}

public static void main( String[] args )
{
Session mysqlSession = mySQLSessionFactory.openSession();
Session mongoSession = mongoSessionFactory.openSession();
}
}

Is there a way to isolate these session creations so that they do not interfere? Any other suggestions?

Thanks!
-Ashish


Top
 Profile  
 
 Post subject: Re: Mongo and MySQL co-existence
PostPosted: Fri Feb 21, 2014 3:00 am 
Newbie

Joined: Fri Feb 21, 2014 2:40 am
Posts: 2
I made a mistake in posting the code. I was experimenting to see if there is a org.hibernate.ogm.SessionFactory to isolate these two factories, and by mistake I posted that in the code. The actual buildMongoSessionFactory is -

private static SessionFactory buildMongoSessionFactory() {
OgmConfiguration configuration=new OgmConfiguration();
configuration.configure("mongdb.cfg.xml");
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}

Sorry for the confusion.


Top
 Profile  
 
 Post subject: Re: Mongo and MySQL co-existence
PostPosted: Wed Feb 26, 2014 4:02 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi Ashish,

Could you try the latest release (4.1.0.Beta1, see [1]) and check whether you still get the problem then? I believe you're running into OGM-416 [2] which was fixed in 4.1 Beta1.

Thanks,

--Gunnar

[1] http://in.relation.to/Bloggers/HibernateOGM410Beta1IsOut
[2] https://hibernate.atlassian.net/browse/OGM-416

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


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