12 Replies Latest reply on Jun 3, 2003 3:16 PM by nbirch

    Can getUnderlyingPreparedStatement() be used with CMP? (auto

    steinarc

      I'm trying to figure out the simplest way of auto generating primary keys for my EJB's.

      I know that using DBMS maintained automatic generation of PK's are not portable, but I don't care (I'm not likely to change from Jboss :-))

      So, is there any way I can use the auto_increment feature in mySQL with CMP entity beans? I've read about the getUnderlyingPreparedStatement(), but I can't figure out how to get hold of the connection from my EJB.

      I would rather not use BMP for now, as I'm lazy and want Jboss to do most of the job for me.

      Any other solution (pattern) would also be greatly appreciated.

        • 1. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
          dsundstrom

          Use of auto number pk columns won't be supported until JDBC 3.0 drivers are available. JDBC 3.0 supports result sets from update queries.

          • 2. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
            jfifield

            Check out "Primary Key Generation Strategies" at http://www.theserverside.com/resources/patterns_review.jsp. I personally use the Sequence Block pattern described in that document. It has been working quite well for me.

            Joe

            • 3. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
              steinarc

              Thanks, I have done just that, and it works fine. I had to rewrite the stuff to take away the local interface stuff, since JBoss 2.4.x does not support that. From what I understand there is no need for this anyway, since JBoss will convert remote calls into local calls if both beans reside in the same JVM?

              • 4. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                sheepe

                > From what I understand there is no need for this anyway, since JBoss will convert remote calls into local calls if both beans reside in the same JVM?

                Huh? Can anyone explain this statement please? We're talking about auto-local relationships, or what? :O

                • 5. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                  dsundstrom

                  No, he is refering to the optimized stack. Local interfaces are suuported in 2.4.4.

                  • 6. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                    jimotte

                    Are you sure that 2.4.4 is supporting local interfaces? I have a stateless session bean I set up as a local interface- it deploys just fine and it has a JNDI name associated with it (I can tell from port 8082)- but when I go to do a lookup I get an error stating it is not bound-
                    (the other remote beans I have deployed are found just fine using same lookup- and I am not using the remote narrow for the local lookup)!!

                    Object obj = getInitialContext().lookup("PageDimensionSessionBean");

                    Is JBoss not binding local Interface EJB's- or am I missing something??
                    Part of My deployment descriptor:

                    <ejb-name>PageDimensionSessionBean</ejb-name>

                    <local-home>com.company.aq.session.PageDimensionSessionHome</local-home>
                    com.company.aq.session.PageDimensionSession
                    <ejb-class>com.company.aq.session.PageDimensionSessionBean</ejb-class>
                    <session-type>Stateless</session-type>
                    <transaction-type>Container</transaction-type>


                    • 7. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                      jimotte

                      I believe local interfaces is supported in 3.0- has anyone tried it there yet?- if so are the lookups the same as for remote lookups - I mean the JNDI name lookups - I realize there is no remote narrowing- Also are the deployment descriptors for the local interfaces done by the spec- with just the local and local-home tags needed ?

                      • 8. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                        jfifield

                        Yes, local interfaces work in 3.0. The ejb-jar.xml is setup per the ejb spec as you stated. The only thing you need to be aware of is JBoss automatically binds the local interfaces to the name local/, but this can be changed using the <local-jndi-name> element in jboss.xml.

                        Joe

                        • 9. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                          jimotte

                          Is this only in 3.0?- when I try it in 2.4.4 with the following bit of deployment descriptor:

                          <ejb-name>PageDimensionSessionBean</ejb-name>
                          <local-jndi-name>PageDimensionSessionBean</local-jndi-name>
                          <local-home>com.company.aq.session.PageDimensionSessionHome</local-home>
                          com.company.aq.session.PageDimensionSession
                          <ejb-class>com.company.aq.session.PageDimensionSessionBean</ejb-class>
                          <session-type>Stateless</session-type>
                          <transaction-type>Container</transaction-type>



                          and my lookup is :

                          Object obj = new InitialContext().lookup("local/PageDimensionSessionBeanPage");

                          I still get :

                          [ERROR,EJBUtil] Failed initializing bean access.
                          [ERROR,Default] javax.naming.NameNotFoundException: local not bound
                          [ERROR,Default] at org.jnp.server.NamingServer.getBinding(NamingServer.j
                          ava:495)

                          which is the same error I get when I lookup like this:

                          Object obj = new InitialContext().lookup("PageDimensionSessionBean");

                          the error:

                          [ERROR,EJBUtil] Failed initializing bean access.
                          [ERROR,Default] javax.naming.NameNotFoundException: PageDimensionSessionBean not
                          bound

                          even though I can clearly see the name on port 8082 and when JBoss starts I get the following message:

                          [INFO,PageDimensionSessionBean] Initializing
                          [INFO,PageDimensionSessionBean] Initialized
                          [INFO,PageDimensionSessionBean] Starting
                          [INFO,PageDimensionSessionBean] Started

                          so can I expect this only in 3.0 or am I still not doing the lookup correctly for local interfaces (the remote lookups do just fine with the preceeding lookup)?
                          Thanks for any help

                          • 10. Re: Can getUnderlyingPreparedStatement() be used with CMP? (

                            Not sure why this discussion is in the database forum.:-)

                            If you look in standardjboss.xml you will see
                            <container-invoker-conf>true</container-invoker-conf>

                            This means you can code as though the bean is remote
                            but jboss will turn it into a local invocation.

                            See
                            org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.java
                            invokeContainer()
                            and
                            org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.java
                            invokeHome() and invoke()

                            For a previous discussion about configuration have
                            a look at
                            http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/
                            Particulary the comments by andreas.

                            Regards,
                            Adrian

                            • 11. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                              jmejia424

                              Do you have an implementation (example) that you might share with me?

                              I am trying to use SQL Server 2000 with an already existing application that uses Auto-Numbers. I do not have the luxury of rewriting the application to use a different form of unique number ID's. Hence, my only option, I believe, is to write my EJB application using BMP's instead of CMP's. I would love to use CMP instead of BMP however, I am not sure if it can be done.

                              Any help would be greatly appreciated.

                              • 12. Re: Can getUnderlyingPreparedStatement() be used with CMP? (
                                nbirch

                                Hi,

                                Unfortunately these links don't work.

                                I'm running Jboss 3.0.2, and all my beans are Startdard CMP. Does the Optimized parameter apply to Standard CMP EJBs (as opposed to CMP2.0 EJBs)?

                                Thanks
                                Nbirch