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
|