2 Replies Latest reply on May 23, 2002 5:25 PM by Jason Stull

    Entity Bean lookup by Primary Key fails in JBoss 3.0RC3

    Jason Newbie

      Hello,
      I'm trying to do a simple "findByPrimaryKey(Integer id)" in JBoss 3.0CR3 and the sql query that JBoss is generating is kooky. The end result on the client side is a FinderException. Here is the server log entry:

      2002-05-23 14:41:55,855 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.User.findByPrimaryKey] Executing SQL: SELECT UserId FROM User WHERE UserId=?
      2002-05-23 14:41:55,855 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.User.findByPrimaryKey] Find failed
      java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'User'.

      The problem seems to be the ? mark in the "Where UserId=?"
      I'm using a sqlserver 2000 datasource which seems to load fine.
      EJB deployment seems ok, too. It recognizes that the User table exists in the db. I have set the default datasource to MSSQLDS in standardjbosscmp-jdbc.xml. This seemed to be Ok in JBoss 2.4.4

      If anyone has any insight in to this, I'm a beggin' for help. Here is some relevent configuration info, sorry about the long post, but I couldn't get any files uploaded:

      login-config.xml

      <application-policy name = "MSSQLDbRealm">

      <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
      <module-option name = "principal">sa</module-option>
      <module-option name = "userName">sa</module-option>
      <module-option name = "password">0455ssej</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
      </login-module>

      </application-policy>


      mssql-service.xml



      <!-- ======================================================================-->
      <!-- New ConnectionManager setup for Microsoft SQL Server 2000 driver -->
      <!-- You may download the latest Microsoft JDBC driver from *Microsoft* -->
      <!-- http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml&frame=true -->
      <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
      <!-- ===================================================================== -->



      <!-- Include a login module configuration named MSSQLDbRealm.
      Update your login-conf.xml, here is an example for a
      ConfiguredIdentityLoginModule:

      <application-policy name = "MSSQLDbRealm">

      <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
      <module-option name = "principal">yourprincipal</module-option>
      <module-option name = "userName">yourusername</module-option>
      <module-option name = "password">yourpassword</module-option>
      <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
      </login-module>

      </application-policy>

      NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
      module-option name = "managedConnectionFactoryName"
      must match the object name of the ConnectionManager you are configuring here.
      -->
      <!--comment out this line if you want component managed security or want
      to use the default values in the ManagedConnectionFactoryProperties -->
      MSSQLDbRealm

      <depends optional-attribute-name="ManagedConnectionFactoryName">
      <!--embedded mbean-->


      MSSQLDS



      <config-property name="ConnectionURL" type="java.lang.String">jdbc:microsoft:sqlserver://172.16.30.99:1433;DatabaseName=MCC</config-property>
      <config-property name="DriverClass" type="java.lang.String">com.microsoft.jdbc.sqlserver.SQLServerDriver</config-property>
      <!--set these only if you want only default logins, not through JAAS
      <config-property name="UserName" type="java.lang.String"></config-property>
      <config-property name="Password" type="java.lang.String"></config-property>
      -->



      <!--Below here are advanced properties -->
      <!--hack-->
      <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper



      <depends optional-attribute-name="ManagedConnectionPool">
      <!--embedded mbean-->


      0
      50
      5000
      15
      <!--criteria indicates if Subject (from security domain) or app supplied
      parameters (such as from getConnection(user, pw)) are used to distinguish
      connections in the pool. Choices are
      ByContainerAndApplication (use both),
      ByContainer (use Subject),
      ByApplication (use app supplied params only),
      ByNothing (all connections are equivalent, usually if adapter supports
      reauthentication)-->
      ByContainer



      <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager

      <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:name=JaasSecurityManager

      java:/TransactionManager
      <!--make the rar deploy! hack till better deployment-->
      jboss.jca:service=RARDeployer





      ejb-jar.xml

      <ejb-jar>
      <enterprise-beans>

      <display-name>User</display-name>
      <ejb-name>User</ejb-name>
      com.mcc.user.ejb.UserRemoteHome
      com.mcc.user.ejb.UserRemote
      <local-home>com.mcc.user.ejb.UserHome</local-home>
      com.mcc.user.ejb.User
      <ejb-class>com.mcc.user.ejb.UserBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>User</abstract-schema-name>
      <cmp-field>
      <field-name>id</field-name>
      </cmp-field>
      <primkey-field>id</primkey-field>

      </enterprise-beans>
      </ejb-jar>

      jboss.xml


      <enterprise-beans>

      <ejb-name>User</ejb-name>
      <jndi-name>UserRemote</jndi-name>

      </enterprise-beans>


      jbosscmp-jdbc.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
      <jbosscmp-jdbc>
      <enterprise-beans>

      <ejb-name>User</ejb-name>
      <table-name>User</table-name>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>UserId</column-name>
      </cmp-field>

      </enterprise-beans>
      </jbosscmp-jdbc>

      Thanks very much,
      j

        • 1. Re: Entity Bean lookup by Primary Key fails in JBoss 3.0RC3
          pete Newbie

          Hi jstull,

          I think the problem is with the table named 'user' in your database (a reserved word in SQL). Try renaming the table to appUser or something like that and updating your jbosscmp-jdbc.xml to bind the User abstract schema to the appUser table.

          hth
          -p

          > java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'User'.

          • 2. Re: Entity Bean lookup by Primary Key fails in JBoss 3.0RC3
            Jason Stull Newbie

            Wow! Thanks, Pete. You were dead on. For other newbies, here is a crude, inelegant example of a basic entity bean configuration for JBoss 3.0RC3 w\ SQLServer 2000 datasource. It works now. All database names and passwords have been changed to protect the innocent:

            conf\login-config.xml

            <application-policy name = "MSSQLDbRealm">

            <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
            <module-option name = "principal">sa</module-option>
            <module-option name = "userName">sa</module-option>
            <module-option name = "password">0455ssej</module-option>
            <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
            </login-module>

            </application-policy>


            deploy\mssql-service.xml



            <!-- ======================================================================-->
            <!-- New ConnectionManager setup for Microsoft SQL Server 2000 driver -->
            <!-- You may download the latest Microsoft JDBC driver from *Microsoft* -->
            <!-- http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/MSDN-FILES/027/001/779/msdncompositedoc.xml&frame=true -->
            <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
            <!-- ===================================================================== -->



            <!-- Include a login module configuration named MSSQLDbRealm.
            Update your login-conf.xml, here is an example for a
            ConfiguredIdentityLoginModule:

            <application-policy name = "MSSQLDbRealm">

            <login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required">
            <module-option name = "principal">yourprincipal</module-option>
            <module-option name = "userName">yourusername</module-option>
            <module-option name = "password">yourpassword</module-option>
            <module-option name = "managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MSSQLDS</module-option>
            </login-module>

            </application-policy>

            NOTE: the application-policy name attribute must match SecurityDomainJndiName, and the
            module-option name = "managedConnectionFactoryName"
            must match the object name of the ConnectionManager you are configuring here.
            -->
            <!--comment out this line if you want component managed security or want
            to use the default values in the ManagedConnectionFactoryProperties -->
            MSSQLDbRealm

            <depends optional-attribute-name="ManagedConnectionFactoryName">
            <!--embedded mbean-->


            MSSQLDS



            <config-property name="ConnectionURL" type="java.lang.String">jdbc:microsoft:sqlserver://172.16.30.99:1433;DatabaseName=MCC</config-property>
            <config-property name="DriverClass" type="java.lang.String">com.microsoft.jdbc.sqlserver.SQLServerDriver</config-property>
            <!--set these only if you want only default logins, not through JAAS
            <config-property name="UserName" type="java.lang.String"></config-property>
            <config-property name="Password" type="java.lang.String"></config-property>
            -->



            <!--Below here are advanced properties -->
            <!--hack-->
            <depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper



            <depends optional-attribute-name="ManagedConnectionPool">
            <!--embedded mbean-->


            0
            50
            5000
            15
            <!--criteria indicates if Subject (from security domain) or app supplied
            parameters (such as from getConnection(user, pw)) are used to distinguish
            connections in the pool. Choices are
            ByContainerAndApplication (use both),
            ByContainer (use Subject),
            ByApplication (use app supplied params only),
            ByNothing (all connections are equivalent, usually if adapter supports
            reauthentication)-->
            ByContainer



            <depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager

            <depends optional-attribute-name="JaasSecurityManagerService">jboss.security:name=JaasSecurityManager

            java:/TransactionManager
            <!--make the rar deploy! hack till better deployment-->
            jboss.jca:service=RARDeployer





            Meta-inf\ejb-jar.xml

            <ejb-jar>
            <enterprise-beans>

            <display-name>User</display-name>
            <ejb-name>User</ejb-name>
            com.mcc.user.ejb.UserRemoteHome
            com.mcc.user.ejb.UserRemote
            <local-home>com.mcc.user.ejb.UserHome</local-home>
            com.mcc.user.ejb.User
            <ejb-class>com.mcc.user.ejb.UserBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.Integer</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>User</abstract-schema-name>
            <cmp-field>
            <field-name>id</field-name>
            </cmp-field>
            <primkey-field>id</primkey-field>

            </enterprise-beans>
            </ejb-jar>

            Meta-inf\jboss.xml


            <enterprise-beans>

            <ejb-name>User</ejb-name>
            <jndi-name>UserRemote</jndi-name>

            </enterprise-beans>


            Meta-inf\jbosscmp-jdbc.xml

            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">
            <jbosscmp-jdbc>
            <enterprise-beans>

            <ejb-name>User</ejb-name>
            <table-name>AppUser</table-name>
            <cmp-field>
            <field-name>id</field-name>
            <column-name>UserId</column-name>
            </cmp-field>

            </enterprise-beans>
            </jbosscmp-jdbc>