2 Replies Latest reply on Dec 15, 2002 9:25 PM by g_spelvin

    CMP with Postgres

    g_spelvin

      Problem: entity bean not stored in postgres, but is looked up there.

      Result: postgres returns SQLException: Relation "helloentity" does not exist

      JBoss postgress datasource config:

      Removed both hs plugin and driver jars from server/default/lib/

      Removed hsqldb-service.xml from server/default/deploy/

      Added postgres-service.xml to server/default/deploy/
      (tried both jndi names as PostgresDS or DefaultDS and matched name in server/default/conf/standardjaws.xml and server/default/conf/standardjbosscmp-jdbc.xml)

      Edited server/default/conf/login-config.xml


      Added postgress pg73j2ee.jar to lib/

      JBoss in its default configuration worked well with the Hypersonic db and was able to persist and look up entity beans. In the current config, this is what JBoss writes out when deploying the app:

      14:44:00,250 INFO [MainDeployer] Starting deployment of package: file:/usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/HelloEntity.ear
      14:44:00,289 INFO [EARDeployer] Init J2EE application: file:/usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/HelloEntity.ear
      14:44:01,373 INFO [EjbModule] Creating
      14:44:01,446 INFO [EjbModule] Deploying HelloEntity
      14:44:04,143 INFO [JDBCInitCommand] Table 'HelloEntity' already exists
      14:44:04,329 INFO [EjbModule] Created
      14:44:04,334 INFO [EjbModule] Starting
      14:44:04,573 INFO [EjbModule] Started
      14:44:04,979 INFO [EmbeddedCatalinaService41] deploy, ctxPath=/HelloEntity, warUrl=file:/usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/server/default/tmp/deploy/server/default/deploy/HelloEntity.ear/87.HelloEntity.ear-contents/HelloEntity.war
      14:44:05,208 INFO [Engine] WebappLoader[/HelloEntity]: Deploying class repositories to work directory /usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/tomcat-4.1.x/work/MainEngine/localhost/HelloEntity
      14:44:05,252 INFO [Engine] WebappLoader[/HelloEntity]: Deploy class files /WEB-INF/classes to /usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/tomcat-4.1.x/work/MainEngine/localhost/HelloEntity/WEB-INF/classes
      14:44:06,370 INFO [Engine] ContextConfig[/HelloEntity]: Added certificates -> request attribute Valve
      14:44:07,539 INFO [EmbeddedCatalinaService41] Using Java2 parent classloader delegation: true
      14:44:07,543 INFO [Engine] StandardManager[/HelloEntity]: Seeding random number generator class java.security.SecureRandom
      14:44:07,548 INFO [Engine] StandardManager[/HelloEntity]: Seeding of random number generator has been completed
      14:44:07,651 INFO [Engine] StandardWrapper[/HelloEntity:default]: Loading container servlet default
      14:44:07,656 INFO [Engine] StandardWrapper[/HelloEntity:invoker]: Loading container servlet invoker
      14:44:07,765 INFO [MainDeployer] Deployed package: file:/usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/HelloEntity.ear

      Servlet code:
      ctx = new InitialContext();
      home = (HelloEntityHome) PortableRemoteObject.narrow(ctx.lookup("HelloEntity"),
      HelloEntityHome.class);

      ejb-jar.xml:

      Person bean
      <ejb-name>HelloEntity</ejb-name>
      HelloEntityHome
      HelloEntity
      <ejb-class>HelloEntityEJB</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      <primkey-field>name</primkey-field>
      False
      <cmp-field><field-name>name</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>



      Where then is the bean stored? Could this be a problem in tomcat config? I logged in to psql monitor and can't see any HelloEntity table, but I see the error as it occurs.

      Any help will be greatly appreciated.

        • 1. Re: CMP with Postgres [more info:]
          g_spelvin

          Samples under jmx-console:

          jndiName=HelloEntity,service=EJB
          service=LocalTxPool,name=PostgresDS
          service=LocalTxDS,name=PostgresDS
          service=LocalTxCM,name=PostgresDS

          jndi-view:
          Ejb Module: file%/usr/local/jboss/jboss-3.0.4_tomcat-4.1.12/server/default/tmp/deploy/server/default/deploy/HelloEntity.ear/88.HelloEntity.ear-contents/HelloEntity.jar

          java:comp namespace of the HelloEntity bean:

          +- env (class: org.jnp.interfaces.NamingContext)


          I've also tried the Oreilly Workbook example and it appears to be suffering from the exact same problems. When building with Ant, I get an exception from Postgres that the Relation does not exist.

          • 2. Postgres specific problem, works w/ mysql
            g_spelvin

            I set up a MySql service file, matched the names in where necessary, and it works fine.

            It seems that the postgres driver is not working correctly w/ jboss. For reference, postgres 7.2.3 server, I tried both pg73jdbc.jar pg73jdbc2ee.jar on Mac OS X 10.2.2

            Specifically, the difference is obvious when deploying the bean:

            When running under postgres-service:
            14:44:01,373 INFO [EjbModule] Creating
            14:44:01,446 INFO [EjbModule] Deploying HelloEntity
            14:44:04,143 INFO [JDBCInitCommand] Table 'HelloEntity' already exists
            14:44:04,329 INFO [EjbModule] Created

            When running under mysql-service:
            18:15:35,231 INFO [EjbModule] Creating
            18:15:35,322 INFO [EjbModule] Deploying HelloEntity
            18:15:36,719 INFO [JDBCInitCommand] Created table 'HelloEntity' successfully.
            18:15:36,733 INFO [EjbModule] Created

            postgres-service.xml:
            &lt;?xml version="1.0" encoding="UTF-8"?&gt;

            &lt;!-- ======================================================================================== --&gt;
            &lt;!-- New ConnectionManager setup for default PostgreSQL dbs --&gt;
            &lt;!-- Build jmx-api (build/build.sh all) and view for config documentation --&gt;
            &lt;!-- To avoid class not found headaches, copy your postgres driver to the jboss lib directory --&gt;
            &lt;!-- ======================================================================================== --&gt;

            &lt;server&gt;

            &lt;mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" name="jboss.jca:service=LocalTxCM,name=PostgresDS"&gt;
            &lt;!-- ======================================================= --&gt;
            &lt;!-- You must include a login module configuration named PostgresDbRealm
            in your login-conf.xml, here is an example for a
            ConfiguredIdentityLoginModule:

            &lt;application-policy name = "PostgresDbRealm"&gt;
            &lt;authentication&gt;
            &lt;login-module code = "org.jboss.resource.security.ConfiguredIdentityLoginModule" flag = "required"&gt;
            &lt;module-option name = "principal"&gt;yourprincipal&lt;/module-option&gt;
            &lt;module-option name = "userName"&gt;yourusername&lt;/module-option&gt;
            &lt;module-option name = "password"&gt;yourpassword&lt;/module-option&gt;
            &lt;module-option name = "managedConnectionFactoryName"&gt;jboss.jca:service=LocalTxCM,name=PostgresDS&lt;/module-option&gt;
            &lt;/login-module&gt;
            &lt;/authentication&gt;
            &lt;/application-policy&gt;

            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.
            --&gt;
            &lt;!-- ===================================================================== --&gt;
            &lt;!--uncomment out this line if you are using the PostgresDbRealm above --&gt;
            &lt;attribute name="SecurityDomainJndiName"&gt;PostgresDbRealm&lt;/attribute&gt;

            &lt;depends optional-attribute-name="ManagedConnectionFactoryName"&gt;
            &lt;!--embedded mbean--&gt;
            &lt;mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=PostgresDS"&gt;
            &lt;!-- ========== Set the JndiName ======================= --&gt;
            &lt;attribute name="JndiName"&gt;PostgresDS&lt;/attribute&gt;
            &lt;attribute name="ManagedConnectionFactoryProperties"&gt;
            &lt;properties&gt;
            &lt;config-property name="ConnectionURL" type="java.lang.String"&gt;jdbc:postgresql://localhost:5432/mydb&lt;/config-property&gt;
            &lt;config-property name="DriverClass" type="java.lang.String"&gt;org.postgresql.Driver&lt;/config-property&gt;
            &lt;!--set these only if you want only default logins, not through JAAS --&gt;
            &lt;config-property name="UserName" type="java.lang.String"&gt;&lt;/config-property&gt;
            &lt;config-property name="Password" type="java.lang.String"&gt;&lt;/config-property&gt;
            &lt;/properties&gt;

            &lt;/attribute&gt;

            &lt;!--Below here are advanced properties --&gt;
            &lt;!--hack--&gt;
            &lt;depends optional-attribute-name="OldRarDeployment"&gt;jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper&lt;/depends&gt;

            &lt;!--real attributes--&gt;
            &lt;/mbean&gt;
            &lt;/depends&gt;

            &lt;depends optional-attribute-name="ManagedConnectionPool"&gt;
            &lt;!--embedded mbean--&gt;
            &lt;mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" name="jboss.jca:service=LocalTxPool,name=PostgresDS"&gt;

            &lt;attribute name="MinSize"&gt;0&lt;/attribute&gt;
            &lt;attribute name="MaxSize"&gt;50&lt;/attribute&gt;
            &lt;attribute name="BlockingTimeoutMillis"&gt;5000&lt;/attribute&gt;
            &lt;attribute name="IdleTimeoutMinutes"&gt;15&lt;/attribute&gt;
            &lt;!--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)--&gt;
            &lt;attribute name="Criteria"&gt;ByContainer&lt;/attribute&gt;
            &lt;/mbean&gt;

            &lt;/depends&gt;
            &lt;depends optional-attribute-name="CachedConnectionManager"&gt;jboss.jca:service=CachedConnectionManager&lt;/depends&gt;

            &lt;depends optional-attribute-name="JaasSecurityManagerService"&gt;jboss.security:service=JaasSecurityManager&lt;/depends&gt;

            &lt;attribute name="TransactionManager"&gt;java:/TransactionManager&lt;/attribute&gt;
            &lt;!--make the rar deploy! hack till better deployment--&gt;
            &lt;depends&gt;jboss.jca:service=RARDeployer&lt;/depends&gt;


            &lt;/mbean&gt;


            &lt;/server&gt;