Postgres connection Error in BMP based bean

Discussions

EJB programming & troubleshooting: Postgres connection Error in BMP based bean

  1. Postgres connection Error in BMP based bean (1 messages)

    I have developed a simple BMP typed bean in Jboss-3.2.3.
    Backend is postgres-7.4.1.
    1. enclosed postgres.jar in my classpath as well as copied into dir /server/default/lib folder
    2. changed the setting of postgres-ds.xml(located at /server/default/deploy)
    3. changed necessary setting in my postgre-jdbc2-service.xml
    (located at /server/default/deploy/jms)
    compiled all the server side and client side program successful without any error/
    4. depolyed the bean in application server successful.

    when i request a bean thru my client program i m getting following error.

    here i enclose descriptor files and client code


    Error i got
    -----------------


    Buildfile: build.xml

    Run:
         [java] Caught an exception.
         [java] java.rmi.ServerException: RemoteException occurred in server
    thread; nested exception is:
         [java] java.rmi.ServerException: EJBException:; nested exception is:
         [java] javax.ejb.EJBException: ejbCreate: Unable to connect to
    database. Could not enlist in transaction on entering meta-aware
    object!javax.transaction.SystemException: enlistResource failed; -
    nested throwable: (javax.resource.ResourceException: Could not enlist
    in transaction on entering meta-aware
    object!javax.transaction.SystemException: enlistResource failed)
         [java] at
    sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
         [java] at sun.rmi.transport.Transport$1.run(Transport.java:148)
         [java] at java.security.AccessController.doPrivileged(Native Method)
         [java] at
    sun.rmi.transport.Transport.serviceCall(Transport.java:144)
         [java] at
    sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
         [java] at
    sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
         [java] at java.lang.Thread.run(Thread.java:534)
         [java] at
    sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
         [java] at
    sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
         [java] at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
         [java] at
    org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown
    Source)
         [java] at
    org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:135)
         [java] at
    org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
         [java] at
    org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
         [java] at
    org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
         [java] at
    org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:173)
         [java] at
    org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
         [java] at $Proxy0.create(Unknown Source)
         [java] at
    com.client.SavingsAccountClient.main(SavingsAccountClient.java:54)
         [java] Caused by: java.rmi.ServerException: EJBException:; nested
    exception is:
         [java] javax.ejb.EJBException: ejbCreate: Unable to connect to
    database. Could not enlist in transaction on entering meta-aware
    object!javax.transaction.SystemException: enlistResource failed; -
    nested throwable: (javax.resource.ResourceException: Could not enlist
    in transaction on entering meta-aware
    object!javax.transaction.SystemException: enlistResource failed)
         [java] at
    org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:347)
         [java] at
    org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:124)
         [java] at
    org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
         [java] at
    org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:483)
         [java] at org.jboss.ejb.Container.invoke(Container.java:720)
         [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)
         [java] at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         [java] at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         [java] at java.lang.reflect.Method.invoke(Method.java:324)
         [java] at org.jboss.mx.capability.ReflectedMBeanDispatcher.invok









    my ejb-jar.xml file.
    ejb-jar .xml
    ==============
    <?xml version="1.0"?>

    <!DOCTYPE ejb-jar PUBLIC
    "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
    "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

    <ejb-jar>

     <enterprise-beans>
       <entity>
          <description>
                This bean represents a cruise ship.
          </description>
          <ejb-name>SavingAccountEJB</ejb-name>
          <home>com.SavingsAccountHome</home>
          <remote>com.SavingsAccount</remote>
          <ejb-class>com.SavingsAccountBean</ejb-class>
          <persistence-type>Bean</persistence-type>
          <prim-key-class>java.lang.String</prim-key-class>
          <reentrant>False</reentrant>
          <security-identity><use-caller-identity/></security-identity>
          <resource-ref>
               <description>DataSource for the Titan database</description>
               <res-ref-name>jdbc/PostgresDB</res-ref-name>
               <res-type>javax.sql.DataSource</res-type>
               <res-auth>Container</res-auth>
          </resource-ref>
      </entity>
     </enterprise-beans>
    <assembly-descriptor>

       <security-role>
          <description>
             This role represents everyone who is allowed full access to the
    Ship EJB.
          </description>
         <role-name>everyone</role-name>
       </security-role>

       <method-permission>
         <role-name>everyone</role-name>
         <method>
             <ejb-name>SavingAccountEJB</ejb-name>
             <method-name>*</method-name>
         </method>
       </method-permission>

       <container-transaction>
         <method>
            <ejb-name>SavingAccountEJB</ejb-name>
            <method-name>*</method-name>
         </method>
         <trans-attribute>Required</trans-attribute>
       </container-transaction>

     </assembly-descriptor>

    </ejb-jar>


    joss.xml
    --------
    <?xml version="1.0"?>

    <jboss>

       <enterprise-beans>
          <entity>
          <ejb-name>SavingAccountEJB</ejb-name>
          <jndi-name>SavingHomeRemote</jndi-name>
          <resource-ref>
             <res-ref-name>jdbc/PostgresDB</res-ref-name>
             <jndi-name>java:/PostgresDS</jndi-name>
          </resource-ref>
          <configuration-name>Standard BMP EntityBean</configuration-name>
          </entity>
       </enterprise-beans>
    </jboss>

    Client Program
    --------------

    package com.client;
    import java.util.*;
    import java.math.*;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;
    import com.SavingsAccountHome;
    import com.SavingsAccount;
    import com.InsufficientBalanceException;


    public class SavingsAccountClient {

        public static void main(String[] args) {
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
            env.put(Context.PROVIDER_URL,"localhost:1099");
            env.put("java.naming.factory.url.pks","org.jboss.naming:org.jnp.interfaces");

            try {
                Context initial = new InitialContext(env);
                Object objref = initial.lookup("SavingHomeRemote");

                SavingsAccountHome home = (SavingsAccountHome)
    PortableRemoteObject.narrow(objref,
                        SavingsAccountHome.class);

                BigDecimal zeroAmount = new BigDecimal("0.00");
                SavingsAccount duke = home.create("123", "Duke", "Earl",
    zeroAmount);

                duke.credit(new BigDecimal("88.50"));
                duke.debit(new BigDecimal("20.25"));
                BigDecimal balance = duke.getBalance();

                System.out.println("balance = " + balance);
                duke.remove();

                SavingsAccount joe = home.create("836", "Joe", "Jones",
    zeroAmount);

                joe.credit(new BigDecimal("34.55"));
                SavingsAccount jones = home.findByPrimaryKey("836");

                jones.debit(new BigDecimal("2.00"));
                balance = jones.getBalance();
                System.out.println("balance = " + balance);

                SavingsAccount pat = home.create("456", "Pat", "Smith",
    zeroAmount);

                pat.credit(new BigDecimal("44.77"));
                SavingsAccount john = home.create("730", "John", "Smith",
    zeroAmount);

                john.credit(new BigDecimal("19.54"));
                SavingsAccount mary = home.create("268", "Mary", "Smith",
    zeroAmount);

                mary.credit(new BigDecimal("100.07"));

                Collection c = home.findByLastName("Smith");
                Iterator i = c.iterator();

                while (i.hasNext()) {
                    SavingsAccount account = (SavingsAccount) i.next();
                    String id = (String) account.getPrimaryKey();
                    BigDecimal amount = account.getBalance();

                    System.out.println(id + ": " + amount);
                }

                c = home.findInRange(new BigDecimal("20.00"),
                        new BigDecimal("99.00"));
                i = c.iterator();

                while (i.hasNext()) {
                    SavingsAccount account = (SavingsAccount) i.next();
                    String id = (String) account.getPrimaryKey();
                    BigDecimal amount = account.getBalance();

                    System.out.println(id + ": " + amount);
                }

                SavingsAccount pete = home.create("904", "Pete", "Carlson",
                        new BigDecimal("5.00"));
                SavingsAccount sally = home.create("905", "Sally", "Fortney",
                        new BigDecimal("8.00"));

                home.chargeForLowBalance(new BigDecimal("10.00"),
                        new BigDecimal("1.00"));

                BigDecimal reducedAmount = pete.getBalance();

                System.out.println(reducedAmount);
                reducedAmount = sally.getBalance();
                System.out.println(reducedAmount);

                System.exit(0);

            } catch (InsufficientBalanceException ex) {
                System.err.println("Caught an InsufficientBalanceException: "
                        + ex.getMessage());

            } catch (Exception ex) {
                System.err.println("Caught an exception.");
                ex.printStackTrace();
            }
        }
    }
  2. does you postgresql server all tcp connections

    its near the top of the postgresql.config file i think

    as default its set to false