0

I know how to create JNDI datasource in glassfish server for relational database. when I try to create JNDI datasource for mongoDB using datasource connection pool no option available in glassfish. enter image description here

after that I tried with JNDI Custom resource URLObject factory I am getting Error

"URLObjectFactory does not have necessary parameters for URL construction"enter image description here

applicationContext.xml file

Here using JPA properties its working fine for me. Using JNDI not working

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:mvc="http://www.springframework.org/schema/mvc"   
    xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
                       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
                       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<context:component-scan base-package="com.mongo"/> 
<context:annotation-config/>
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="txManager"/>
<jee:jndi-lookup jndi-name="mongo" id="mongoDatasource" />
<bean id="entityManagerFactory"  class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">   
    <property name="persistenceUnitName" value="hbogm" />
    <property name="persistenceProviderClass" value="org.hibernate.ogm.jpa.HibernateOgmPersistence"/>
    <property name="packagesToScan" value="com.mongo.domain"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
    <property name="dataSource" ref="mongoDatasource" />
    <property name="jpaProperties">
        <props>
            <!--<prop key="hibernate.transaction.manager_lookup_class" >org.hibernate.transaction.SunONETransactionManagerLookup</prop>-->
            <prop key="org.hibernate.ogm.dialect">org.hibernate.ogm.dialect.mongodb.MongoDBDialect</prop>
            <prop key="hibernate.ogm.datastore.provider">org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider</prop>
            <!--<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>-->
            <prop key="hibernate.current_session_context_class">jta</prop>
            <!--<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.SunOneJtaPlatform</prop>--> 
            <prop key="hibernate.ogm.datastore.database">nvli</prop>
            <prop key="hibernate.ogm.datastore.username">root</prop>
            <prop key="hibernate.ogm.datastore.password">hcdc123</prop>
            <prop key="hibernate.ogm.mongodb.host">127.0.0.1</prop>
            <prop key="hibernate.ogm.mongodb.port">27017</prop>
            <prop key="hibernate.ogm.datastore.create_database">true</prop>
        </props>
    </property>
</bean>
<bean id="txManager"  class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
Suman Behara
  • 150
  • 9
  • when you say "datasource", you presumably mean "javax.sql.DataSource". I think the clue is in the SQL in that package name ... MongoDB doesn't do SQL, or JDBC. – Neil Stockton Nov 15 '16 at 11:44
  • Possible duplicate of [MongoDb via jndi](http://stackoverflow.com/questions/4076254/mongodb-via-jndi) – Neil Stockton Nov 15 '16 at 11:44
  • @NeilStockton In second image I am passing urlconnection string and its giving "URLObjectFactory does not have necessary parameters for URL construction".could you check and tell what I am missing. how to construct connection string in URL Object factory – Suman Behara Nov 18 '16 at 04:14

0 Answers0