Announcement Announcement Module
Collapse
No announcement yet.
JDNI lookup problem: JBoss + Spring + JPOX Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JDNI lookup problem: JBoss + Spring + JPOX

    Hi everybody,

    I have a problem when try to bind DataSource defined in JBoss configuration file with org.jpox.PersistenceManagerFactoryImpl using Spring 1.2.1:

    Data Source defined in oracle-ds.xml (this file localed in <JBoss Install Dir>/server/default/deploy/)
    <datasources>
    <local-tx-datasource>
    <jndi-name>myDataSource</jndi-name>
    <connection-url>jdbc:oracle:thin:@srv:1521:mydb</connection-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <user-name>app_usr</user-name>
    <password>app_pwd</password>
    <min-pool-size>20</min-pool-size>
    <max-pool-size>40</max-pool-size>
    </local-tx-datasource>
    </datasources>


    Content of the ApplicationContext.xml
    <beans>

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>myDataSource</value>
    </property>
    </bean>

    <bean id="persistenceManagerFactory" class="org.jpox.PersistenceManagerFactoryImpl">
    <property name="connectionFactory"><ref bean="dataSource"/></property>
    <property name="nontransactionalRead"><value>true</value></property>
    <property name="autoCreateSchema"><value>false</value></property>
    <property name="storeDictionaryCaseIdentifier"><value>Preser veCase</value></property>
    <property name="fullyQualifiedNames"><value>true</value></property>
    </bean>
    ..............................
    ..............................
    ..............................
    <bean id="ApplicationParamDAO" class="SomeDAOImpl">
    <property name="persistenceManagerFactory">
    <ref bean="persistenceManagerFactory"/>
    </property>
    </bean>
    </beans>


    there is the simplified code of SomeDAO:
    public class SomeDAOImpl implements SomeDAO{

    private PersistenceManagerFactory persistenceManagerFactory;

    public PersistenceManagerFactory getPersistenceManagerFactory() {
    return persistenceManagerFactory;
    }


    public void setPersistenceManagerFactory(PersistenceManagerFac tory persistenceManagerFactory) {
    this.persistenceManagerFactory = persistenceManagerFactory;
    }
    ........................
    }

    When I try to get persistenceManagerFactory from any DAO i.e. like that:

    .....
    ApplicationContext appContext =
    new ClassPathXmlApplicationContext(paths);
    SomeDAO someDAO = (SomeDAO)appContext.getBean("SomeDAO");
    .....


    I get the following Exception:

    org.jpox.exceptions.UnsupportedConnectionFactoryEx ception: Connection factory (org.springframework.jndi.JndiObjectFactoryBean@17 68b0a) not supported - must be a javax.sql.DataSource

    It seems to me I did something wrong but I couldnot find what exactly... Could anybody help my to resolve the trouble?

    Thanks a lot in advance

    Alex Chesnokov

  • #2
    Well I always find JNDI naming somewhat confusing . . . just looking at a similar set up I have, and where I have

    <jndi-name>myDataSource</jndi-name>

    in my jboss xxx-ds.xml file, I have

    <property name="jndiName">
    <value>java:/myDataSource</value>
    </property>

    in my JndiObjectFactoryBean config.

    Does that help?

    Comment


    • #3
      Hi Chris,

      Originally posted by cmgharris
      Well I always find JNDI naming somewhat confusing . . . just looking at a similar set up I have, and where I have

      <jndi-name>myDataSource</jndi-name>

      in my jboss xxx-ds.xml file, I have

      <property name="jndiName">
      <value>java:/myDataSource</value>
      </property>

      in my JndiObjectFactoryBean config.

      Does that help?
      Thanks for the answer but it still does not work... May be I need to configure something else? e.g. jboss-web.xml or web.xml?

      It seems that JndiObjectFactoryBean found the resource but the PersistenceManagerFactoryImpl is not able to get DataSource using JndiObjectFactoryBean...

      Regards,

      Alex Chesnokov

      Comment


      • #4
        Not sure I can help any further . . .

        May be I need to configure something else? e.g. jboss-web.xml or web.xml?
        I'm pretty sure you don't need anything else like that.

        I have my JndiObjectFactoryBean set up the same as yours, and inject it into a JdbcJTemplate, which is also expecting javax.sql.DataSource, and it works OK. I'm not using Oracle though.

        Your client isn't in a different JVM is it? I'm not sure if that would cause a problem.

        Maybe someone else can shed some light . . .

        Comment


        • #5
          You could try to turn on Spring debugging and look up the log. JNDI support classes have quite a lot of debuging built in.

          Comment


          • #6
            You can try to specify the "proxyInterface" property of JndiObjectFactoryBean with "javax.sql.DataSource".
            Besides that you might try to set the "resourceRef" property to true. Maybe JBoss does not publish the datasource for external access.

            Regards,
            Andreas

            Comment


            • #7
              I don't have any problem with jndi datasource
              I am using Oracle but not with JBoss (I am using Tomcat).

              In Tomcat (5.5.9):
              <Resource
              name="jdbc/mainDb"
              auth="Container"
              type="javax.sql.DataSource"
              maxActive="4" maxIdle="1" maxWait="10000"
              username="xxx"
              password="xxx"
              driverClassName="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@//xxx.xxx.xxx.xxx:1521/xxx"
              removeAbandoned="true"
              removeAbandonedTimeout="60"
              logAbandoned="true" />

              In web.xml:
              <resource-ref>
              <description>DB Connection via Tomcat JNDI</description>
              <res-ref-name>jdbc/mainDb</res-ref-name>
              <res-type>javax.sql.DataSource</res-type>
              <res-auth>Container</res-auth>
              </resource-ref>

              In applicationcontext.xml:
              <bean id="dataSource"
              class="org.springframework.jndi.JndiObjectFactoryB ean"
              lazy-init="true">
              <property name="jndiName">
              <value>java:/comp/env/jdbc/mainDb</value>
              </property>
              </bean>

              Comment


              • #8
                Not sure if this will help, but remote client access to JBoss datasources was not supported until 4.0. This is now possible with a config option in the XX-ds.xml. I have confirmed this works. See http://wiki.jboss.org/wiki/Wiki.jsp?...rceFromAClient

                Comment


                • #9
                  Originally posted by drewcox
                  Not sure if this will help, but remote client access to JBoss datasources was not supported until 4.0. This is now possible with a config option in the XX-ds.xml. I have confirmed this works. See http://wiki.jboss.org/wiki/Wiki.jsp?...rceFromAClient
                  It seems that it's JBoss initialization sequence problem: my application gets initialized _before_ JBoss loads datasources, so if Spring is being initialized at startup (in listener or startup servlet init method), there are no datasources defined yet :-(.

                  Do somebody know how to enforce JBoss to load datasources first?

                  Cheers,
                  Alex

                  Comment


                  • #10
                    You can open the jmx-console and see what it's deployed as if you want to find out JNDI names.

                    JBoss also has a dependency mechanism for specifying dependencies between deployable components, but I don't think you should need this for datasources.

                    Post your stacktrace maybe?

                    Comment


                    • #11
                      Do somebody know how to enforce JBoss to load datasources first?
                      Search their manuals (I think the topic was discussed in the paid ones). I haven't used JBoss in quite some time, but at least in the 3.2.x series you had a depend-on attribute I think in the xml file which specified the things that had to be deployed first before your application.
                      I've tried several solution, but from my experience, finding this configuration parameter was by far the easiest and most efficient one.

                      Comment

                      Working...
                      X