11 Replies Latest reply on Nov 13, 2002 4:21 AM by vicrh

    Error in JBoss with a BMP EJB

    vicrh

      Hello,

      I'm having a strange problem with JBoss 3.0.4. I had to map 3 tables inside one BMP entity bean, and when executing a finder method that returns several remote interfaces of the BMP EJB, I get the next error:

      ----- BEGINNING OF STACK TRACE -----------

      2002-11-07 11:31:03,434 ERROR [org.jboss.ejb.plugins.LogInterceptor] RuntimeException:
      java.lang.IllegalStateException: removing bean lock and it has tx set!PacientesBean org.scs.comun.ejb.PacientesPK@657
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedPessimisticEJBLock.java:427)
      at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:107)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:124)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.Container.invoke(Container.java:712)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1058)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:382)
      at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)

      ----- END OF STACK TRACE -----------

      I first thought the problem was in the defined transaction attributes for the finder methods of the BMP Entity Bean. I tried with the "supports" and "never" attributes for all the finder methods but get the same error when going through the list of returned remote interfaces.

      As I didn't know what to do next, and I thought the bean was well coded, I deployed it in Sun's reference EJB container and found it worked there as expected.

      So, if the same code works fine in the reference EJB container, what is wrong about my bean deployed in the JBoss EJB container? Why does JBoss put the beans in a transaction when the deployment descriptor tells it's not necessary?

      Thank you in advance for your help.

      Regards,
      Victor

        • 1. Re: Error in JBoss with a BMP EJB

          You know ejbFind... should return primary keys not
          remote interfaces, the container generates the
          remote interaces from the keys?

          What are you using as your primary key class?

          It should implement equals(Object) and hashCode()
          correctly.

          I know JBoss2.x used to wrap primary keys in case
          they weren't implemented correctly (maybe the RI
          does the same?)
          This was dropped in 3.x because it was very
          inefficient.

          If this doesn't solve your problem, can you post
          some more info such as relevent code snippets.

          Regards,
          Adrian

          • 2. Re: Error in JBoss with a BMP EJB
            vicrh

            Hello Adrian,

            First of all, thank you for your answer.

            Yes, I return a collection of primary keys inside the ejb's finders implementation. I'm used to speak about a returned collection of remote interfaces because of the declaration of the finder in the home interface.

            As the primary key class, I'm using a composite primary key (3 values), and the hashCode() and equals(Object) methods are aware of them.

            I have seen working with JBoss that if you implement a primary key class in a wrong way, it will warn you of that fact at deploy time. In this case I have seen no complain from JBoss about the primary key class.

            Here are the methods in my primary key class:

            ------------ BEGINNING PK METHODS --------------------

            public boolean equals(Object obj) {
            boolean result = false;

            if (obj != null && obj instanceof PacientesPK) {
            PacientesPK otro = (PacientesPK) obj;

            if (this.idPaciente == null && otro.getIdPaciente() == null && this.codCip == null &&
            otro.getCodCip() == null && this.secPaciente == null && otro.getSecPaciente() == null)
            result = true;
            else if (this.idPaciente != null && otro.getIdPaciente() != null && this.idPaciente.equals(otro.getIdPaciente()))
            result = true;
            else if (this.codCip != null && otro.getCodCip() != null && this.codCip.equals(otro.getCodCip()))
            result = true;
            else if (this.secPaciente != null && otro.getSecPaciente() != null && this.secPaciente.equals(otro.getSecPaciente()))
            result = true;
            }
            return result;
            }

            public int hashCode() {
            int code;

            if (this.idPaciente == null && this.codCip == null && this.secPaciente == null)
            code = (new Long(System.currentTimeMillis())).hashCode();
            else {
            code = 0;
            if (this.idPaciente != null)
            code += this.idPaciente.hashCode();
            if (this.codCip != null)
            code += this.codCip.hashCode();
            if (this.secPaciente != null)
            code += this.secPaciente.hashCode();
            }
            return code;
            }

            ------------ END PK METHODS --------------------

            Here is the part of my sample program that tests the BMP bean:

            ----------- BEGINNING OF TEST CODE ---------------
            Collection lista = home.findByApellidos("DIAZ", null);
            Iterator iterador = lista.iterator();
            while (iterador.hasNext()) {
            Pacientes pac = (Pacientes) iterador.next();
            PacientesData dp = pac.getAll();
            System.out.println("- " + dp.getNombre() + " " + dp.getApellido1() + " " + dp.getApellido2());
            }
            ----------- END OF TEST CODE ---------------

            I think the implementation is ok, and what is strange for me is that the bean works fine in Sun's reference implementation, but fails to do so in JBoss.

            When the list of PK returned by the finder is larger than
            20 elements aprox. the test program stalls and then the server throws the exception.

            Regards,
            Victor

            • 3. Re: Error in JBoss with a BMP EJB

              Can you post a small example that reproduces the
              problem.
              I will debug it, to see whether it is your problem
              or a bug in JBoss.

              Regards,
              Adrian

              • 4. Re: Error in JBoss with a BMP EJB
                vicrh

                Hello Adrian,

                I as this BMP EJB is quite complex, I took some time to make it simpler, so there was no use of DAO classes, etc ...

                The test program simply calls a finder whichs return a list of people, usually from 2 of the 3 tables wrapped by this bmp bean.

                Here is the code for the primary key class:

                ----------- BEGINNING OF PRIMARY KEY CLASS --------------
                package ejb.test;

                import java.io.Serializable;

                /**
                *
                * @author Vctor Rodrguez Herreros
                */
                public class PacientesPK implements Serializable {
                protected Long idPaciente;
                protected String codCip;
                protected Long secPaciente;

                /** Creates a new instance of PacientesPK */
                public PacientesPK() {
                this.idPaciente = null;
                this.codCip = null;
                this.secPaciente = null;
                }

                public PacientesPK(Long l) {
                this.idPaciente = l;
                this.codCip = null;
                this.secPaciente = null;
                }

                public PacientesPK(Long l1, String s, Long l2) {
                this.idPaciente = l1;
                this.codCip = s;
                this.secPaciente = l2;
                }

                public Long getIdPaciente() {
                return idPaciente;
                }

                public void setIdPaciente(Long l) {
                this.idPaciente = l;
                }

                public String getCodCip() {
                return codCip;
                }

                public void setCodCip(String s) {
                this.codCip = s;
                }

                public Long getSecPaciente() {
                return secPaciente;
                }

                public void setSecPaciente(Long l) {
                this.secPaciente = l;
                }

                public boolean equals(Object obj) {
                boolean result = false;

                if (obj != null && obj instanceof PacientesPK) {
                PacientesPK otro = (PacientesPK) obj;

                if (this.idPaciente == null && otro.getIdPaciente() == null && this.codCip == null &&
                otro.getCodCip() == null && this.secPaciente == null && otro.getSecPaciente() == null)
                result = true;
                else if (this.idPaciente != null && otro.getIdPaciente() != null && this.idPaciente.equals(otro.getIdPaciente()))
                result = true;
                else if (this.codCip != null && otro.getCodCip() != null && this.codCip.equals(otro.getCodCip()))
                result = true;
                else if (this.secPaciente != null && otro.getSecPaciente() != null && this.secPaciente.equals(otro.getSecPaciente()))
                result = true;
                }
                return result;
                }

                public int hashCode() {
                int code;

                if (this.idPaciente == null && this.codCip == null && this.secPaciente == null)
                code = (new Long(System.currentTimeMillis())).hashCode();
                else {
                code = 0;
                if (this.idPaciente != null)
                code += this.idPaciente.hashCode();
                if (this.codCip != null)
                code += this.codCip.hashCode();
                if (this.secPaciente != null)
                code += this.secPaciente.hashCode();
                }
                return code;
                }

                }

                ----------- END OF PRIMARY KEY CLASS --------------

                Now here goes the data class which I use to represent all the data I need from the tables:

                ----------- BEGINNING OF DATA CLASS --------------
                package ejb.test;

                import java.sql.Date;

                /**
                *
                * @author Vctor Rodrguez Herreros
                */
                public class PacientesData extends PacientesPK {
                protected String nombre;
                protected String apellido1;
                protected String apellido2;
                protected String sexo;
                protected Date fechaNacimiento;
                protected String nass;
                protected String dni;
                protected String telefono1;
                protected String direccion;
                protected String codPostal;

                /** Creates a new instance of PacientesData */
                public PacientesData() {
                }

                public String getNombre() {
                return nombre;
                }

                public void setNombre(String s) {
                this.nombre = s;
                }

                public String getApellido1() {
                return apellido1;
                }

                public void setApellido1(String s) {
                this.apellido1 = s;
                }

                public String getApellido2() {
                return apellido2;
                }

                public void setApellido2(String s) {
                this.apellido2 = s;
                }

                public String getSexo() {
                return sexo;
                }

                public void setSexo(String s) {
                this.sexo = s;
                }

                public Date getFechaNacimiento() {
                return fechaNacimiento;
                }

                public void setFechaNacimiento(Date d) {
                this.fechaNacimiento = d;
                }

                public String getNass() {
                return nass;
                }

                public void setNass(String s) {
                this.nass = s;
                }

                public String getDni() {
                return dni;
                }

                public void setDni(String s) {
                this.dni = s;
                }

                public String getTelefono1() {
                return telefono1;
                }

                public void setTelefono1(String s) {
                this.telefono1 = s;
                }

                public String getDireccion() {
                return direccion;
                }

                public void setDireccion(String s) {
                this.direccion = s;
                }

                public String getCodPostal() {
                return codPostal;
                }

                public void setCodPostal(String s) {
                this.codPostal = s;
                }

                }
                ----------- END OF DATA CLASS --------------

                Now the class for the BMP bean:

                ----------- BEGINNING OF BMP BEAN CLASS --------------
                package ejb.test;

                import java.util.Collection;
                import java.sql.*;
                import javax.sql.*;
                import java.util.*;
                import java.rmi.RemoteException;
                import javax.ejb.*;
                import javax.naming.*;

                /**
                *
                * @author Vctor Rodrguez Herreros
                */
                public class PacientesBean extends PacientesData implements EntityBean {

                private Connection con;
                public EntityContext context;
                private String dbName = "java:/RacpDB"; // To use with Jboss
                //private String dbName = "jdbc/Racp"; // To use with Sun's reference implementation

                /** Creates a new instance of PacientesBean */
                public PacientesBean() {}

                public PacientesPK ejbFindByPrimaryKey(PacientesPK primaryKey) throws FinderException {
                boolean result;
                Vector resultado;
                PacientesPK pk = null;
                ResultSet rs = null;

                try {
                System.out.println("VICTOR: ejbFindByPrimaryKey ...");
                Statement stmt = con.createStatement();
                if (primaryKey.getIdPaciente() != null) {
                rs = stmt.executeQuery("SELECT IDPACIENTE, NTARJETASANITARIA, SEC_PACIENTE FROM RACPPACIENTES WHERE ID_PACIENTE=" + primaryKey.getIdPaciente());
                if (!rs.next())
                throw new Exception("PK specified not found ...");
                pk = new PacientesPK(new Long(rs.getLong(1)), rs.getString(2), new Long(rs.getLong(3)));
                if (rs.next())
                throw new Exception("multiple matchs for a single PK value ...");
                }
                else if (primaryKey.getCodCip() != null) {
                // Leyendo paciente general de tarjeta sanitaria
                rs = stmt.executeQuery("SELECT COD_CIP FROM TA_TARJETAS WHERE COD_CIP='" + primaryKey.getCodCip() + "'");
                if (!rs.next())
                throw new Exception("PK specified not found ...");
                pk = new PacientesPK(null, rs.getString(1), null);
                if (rs.next())
                throw new Exception("multiple matchs for a single PK value ...");
                }
                else if (primaryKey.getSecPaciente() != null) {
                // Leyendo paciente general de centros concertados
                rs = stmt.executeQuery("SELECT SEC_PACIENTE FROM CC_PACIENTES WHERE SEC_PACIENTE=" + primaryKey.getSecPaciente());
                if (!rs.next())
                throw new Exception("PK specified not found ...");
                pk = new PacientesPK(null, null, new Long(rs.getLong(1)));
                if (rs.next())
                throw new Exception("multiple matchs for a single PK value ...");
                }
                else
                throw new Exception("all PK fields are null ...");
                stmt.close();
                }
                catch (Exception ex) {
                throw new EJBException("ejbFindByPrimaryKey: " + ex.getMessage());
                }
                return pk;
                }

                public Collection ejbFindByApellidos(String apellido1, String apellido2) throws FinderException {
                ArrayList result = null;
                ResultSet rs = null;

                try {
                Statement stmt = con.createStatement();
                if (apellido2 != null)
                rs = stmt.executeQuery("SELECT CUENTA FROM RACP.TA_APELLIDOS_COMUNES WHERE DES_APELLIDO1 = '" + apellido1 + "' AND DES_APELLIDO2 = '" + apellido2 + "'");
                else
                rs = stmt.executeQuery("SELECT SUM(CUENTA) FROM RACP.TA_APELLIDOS_COMUNES WHERE DES_APELLIDO1 = '" + apellido1 + "'");
                while (rs.next()) {
                long cuenta = rs.getLong(1);
                if (cuenta > 200L)
                throw new FinderException("Demasiados resultados. Refine la bsqueda.");
                }
                // Si se puede realizar la bsqueda, entonces realizamos la bsqueda
                // Primero buscamos en TA_TARJETAS
                result = new ArrayList();
                if (apellido2 != null)
                rs = stmt.executeQuery("SELECT COD_CIP FROM TA_TARJETAS WHERE DES_APELLIDO1 = '" + apellido1 + "' AND DES_APELLIDO2 = '" + apellido2 + "'");
                else
                rs = stmt.executeQuery("SELECT COD_CIP FROM TA_TARJETAS WHERE DES_APELLIDO1 = '" + apellido1 + "'");
                while (rs.next()) {
                // Tomamos el valor
                result.add(new PacientesPK(null, rs.getString(1), null));
                }
                // Luego buscamos en CC_PACIENTES
                if (apellido2 != null)
                rs = stmt.executeQuery("SELECT SEC_PACIENTE FROM CC_PACIENTES WHERE APELLIDO1 = '" + apellido1 + "' AND APELLIDO2 = '" + apellido2 + "'");
                else
                rs = stmt.executeQuery("SELECT SEC_PACIENTE FROM CC_PACIENTES WHERE APELLIDO1 = '" + apellido1 + "'");
                while (rs.next()) {
                // Tomamos el valor
                result.add(new PacientesPK(null, null, new Long(rs.getLong(1))));
                }
                stmt.close();
                }
                catch (Exception ex) {
                System.out.println("ejbFindByApellidos: " + ex.getMessage());
                }
                return ((Collection) result);
                }

                public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
                System.out.println("VICTOR: ejbActivate ...");
                PacientesPK clave = (PacientesPK) context.getPrimaryKey();
                this.idPaciente = clave.getIdPaciente();
                this.codCip = clave.getCodCip();
                this.secPaciente = clave.getSecPaciente();
                }

                public void ejbLoad() throws javax.ejb.EJBException, java.rmi.RemoteException {
                Statement stmt = null;
                ResultSet rs = null;

                try {
                System.out.println("VICTOR: ejbLoad (" + idPaciente + ", " + codCip + ", " + secPaciente + ") hashCode = " + (new PacientesPK(idPaciente, codCip, secPaciente)).hashCode() + "...");
                stmt = con.createStatement();
                // Se mira si el paciente tiene tarjeta sanitaria o es de
                // centros concertados
                if (this.codCip != null) {
                // Paciente de tarjeta sanitaria
                rs = stmt.executeQuery("SELECT NUM_NASS, COD_SEXO, DES_NOMBRE, DES_APELLIDO1, FEC_NACIMIENTO, COD_DNI_NIE, DES_APELLIDO2, DES_DIRECCION, COD_POSTAL, NUM_TELEF_PPAL FROM TA_TARJETAS WHERE COD_CIP='" + codCip + "'");
                if (!rs.next())
                throw new Exception("Pacient was not found <" + codCip + "> ...");
                try {
                this.nass = rs.getString(1);
                this.sexo = rs.getString(2);
                this.nombre = rs.getString(3);
                this.apellido1 = rs.getString(4);
                this.fechaNacimiento = new java.sql.Date(((java.util.Date) rs.getTimestamp(5)).getTime());
                this.dni = rs.getString(6);
                this.apellido2 = rs.getString(7);
                this.direccion = rs.getString(8);
                this.codPostal = (new Integer(rs.getInt(9))).toString();
                this.telefono1 = (new Long(rs.getLong(10))).toString();
                }
                catch (Exception e) {}
                stmt.close();
                }
                else if (this.secPaciente != null ) {
                // Paciente de centros cocertados
                rs = stmt.executeQuery("SELECT APELLIDO1, APELLIDO2, NOMBRE, FEC_NACIMIENTO, SEXO, NUM_SS, DIRECCION, COD_POSTAL, DNI, NUM_TELF1 FROM CC_PACIENTES WHERE SEC_PACIENTE=" + secPaciente);
                if (!rs.next())
                throw new Exception("Pacient was not found...");
                try {
                this.apellido1 = rs.getString(1);
                this.apellido2 = rs.getString(2);
                this.nombre = rs.getString(3);
                this.fechaNacimiento = new java.sql.Date(((java.util.Date) rs.getTimestamp(4)).getTime());
                this.sexo = rs.getString(5);
                this.nass = rs.getString(6);
                this.direccion = rs.getString(7);
                this.codPostal = rs.getString(8);
                this.dni = rs.getString(9);
                this.telefono1 = rs.getString(10);
                }
                catch (Exception e) {}
                stmt.close();
                }
                else
                throw new Exception("todas las claves son nulas ...");
                }
                catch (Exception ex) {
                throw new EJBException("ejbLoad: " + ex.getMessage());
                }
                }

                public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
                System.out.println("VICTOR: ejbPassivate ...");
                this.idPaciente = null;
                this.codCip = null;
                this.secPaciente = null;
                }

                public void ejbRemove() throws javax.ejb.RemoveException, javax.ejb.EJBException, java.rmi.RemoteException {
                }

                public void ejbStore() throws javax.ejb.EJBException, java.rmi.RemoteException {

                }

                public void setEntityContext(javax.ejb.EntityContext entityContext) throws javax.ejb.EJBException, java.rmi.RemoteException {
                this.context = entityContext;
                try {
                System.out.println("VICTOR: setEntityContext ...");
                makeConnection();
                }
                catch (Exception ex) {
                throw new EJBException("Unable to connect to database. " + ex.getMessage());
                }
                }

                public PacientesData getAll() {
                PacientesData data = new PacientesData();

                data.setIdPaciente(idPaciente);
                data.setCodCip(codCip);
                data.setSecPaciente(secPaciente);
                data.setNombre(nombre);
                data.setApellido1(apellido1);
                data.setApellido2(apellido2);
                data.setDni(dni);
                data.setNass(nass);
                data.setFechaNacimiento(fechaNacimiento);
                data.setSexo(sexo);
                data.setTelefono1(telefono1);
                data.setCodPostal(codPostal);
                data.setDireccion(direccion);
                return data;
                }

                public void unsetEntityContext() throws javax.ejb.EJBException, java.rmi.RemoteException {
                try {
                System.out.println("VICTOR: unsetEntityContext ...");
                con.close();
                }
                catch (Exception ex) {
                throw new EJBException("unsetEntityContext: " + ex.getMessage());
                }
                }

                /*********************** Database Routines *************************/

                private void makeConnection() throws NamingException, SQLException {

                InitialContext ic = new InitialContext();
                DataSource ds = (DataSource) ic.lookup(dbName);
                con = ds.getConnection(); // To use with JBoss
                //con = ds.getConnection("racp", "racp"); // To use with Sun's reference implementation
                }

                }
                ----------- END OF BMP BEAN CLASS --------------

                The home interface:

                ----------- BEGINNING OF HOME INTERFACE --------------
                package ejb.test;

                import java.rmi.RemoteException;
                import java.util.Collection;
                import javax.ejb.*;

                /**
                *
                * @author Vctor Rodrguez Herreros
                */
                public interface PacientesHome extends EJBHome {

                public Pacientes findByPrimaryKey(PacientesPK primaryKey) throws FinderException, RemoteException;

                public Collection findByApellidos(String apellido1, String apellido2) throws FinderException, RemoteException;

                }
                ----------- END OF HOME INTERFACE --------------

                The remote interface:

                ----------- BEGINNING OF REMOTE INTERFACE --------------
                package ejb.test;

                import java.rmi.RemoteException;
                import java.sql.Date;
                import javax.ejb.EJBObject;

                /**
                *
                * @author Vctor Rodrguez Herreros
                */
                public interface Pacientes extends EJBObject {

                public PacientesData getAll() throws RemoteException;

                }
                ----------- END OF REMOTE INTERFACE --------------

                The deployment descriptor:

                ----------- BEGINNING OF DESCRIPTOR --------------
                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd">

                <ejb-jar>
                <display-name>Pacientes</display-name>
                <enterprise-beans>

                <display-name>PacientesBean</display-name>
                <ejb-name>PacientesBean</ejb-name>
                ejb.test.PacientesHome
                ejb.test.Pacientes
                <ejb-class>ejb.test.PacientesBean</ejb-class>
                <persistence-type>Bean</persistence-type>
                <prim-key-class>ejb.test.PacientesPK</prim-key-class>
                False

                </enterprise-beans>
                <assembly-descriptor>
                <container-transaction>

                <ejb-name>PacientesBean</ejb-name>
                <method-intf>Home</method-intf>
                <method-name>remove</method-name>
                <method-params>
                <method-param>java.lang.Object</method-param>
                </method-params>

                <trans-attribute>Required</trans-attribute>
                </container-transaction>
                <container-transaction>

                <ejb-name>PacientesBean</ejb-name>
                <method-intf>Home</method-intf>
                <method-name>findByApellidos</method-name>
                <method-params>
                <method-param>java.lang.String</method-param>
                <method-param>java.lang.String</method-param>
                </method-params>

                <trans-attribute>Supports</trans-attribute>
                </container-transaction>
                <container-transaction>

                <ejb-name>PacientesBean</ejb-name>
                <method-intf>Home</method-intf>
                <method-name>remove</method-name>
                <method-params>
                <method-param>javax.ejb.Handle</method-param>
                </method-params>

                <trans-attribute>Required</trans-attribute>
                </container-transaction>
                <container-transaction>

                <ejb-name>PacientesBean</ejb-name>
                <method-intf>Remote</method-intf>
                <method-name>getAll</method-name>
                <method-params />

                <trans-attribute>Required</trans-attribute>
                </container-transaction>
                <container-transaction>

                <ejb-name>PacientesBean</ejb-name>
                <method-intf>Home</method-intf>
                <method-name>findByPrimaryKey</method-name>
                <method-params>
                <method-param>ejb.test.PacientesPK</method-param>
                </method-params>

                <trans-attribute>Supports</trans-attribute>
                </container-transaction>
                </assembly-descriptor>
                </ejb-jar>
                ----------- END OF DESCRIPTOR --------------

                And finally the test program:
                ----------- BEGINNING OF TEST CLASS --------------
                import java.util.*;
                import javax.naming.Context;
                import javax.naming.InitialContext;
                import javax.rmi.PortableRemoteObject;

                //import org.scs.comun.ejb.*;
                import ejb.test.*;
                /**
                *
                * @author Vctor Rodrguez Herreros
                */
                public class BMPTest {

                /** Creates a new instance of EjbTest */
                public BMPTest() {
                }

                /**
                * @param args the command line arguments
                */
                public static void main(String[] args) {
                try
                {
                // Get a naming context
                Properties p = new Properties();
                p.put(Context.PROVIDER_URL, "jnp://zeus:1099");
                p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                InitialContext jndiContext = new InitialContext(p);
                System.out.println("Got context");

                Object ref = jndiContext.lookup("PacientesBean");
                PacientesHome home = (PacientesHome)
                PortableRemoteObject.narrow(ref, PacientesHome.class);

                // Search by first surname
                Collection lista = home.findByApellidos("DIAZ", null);
                Iterator iterador = lista.iterator();
                System.out.println("Finder result:\n");
                while (iterador.hasNext()) {
                Pacientes pac = (Pacientes) iterador.next();
                PacientesData dp = pac.getAll();
                System.out.println("- " + dp.getNombre() + " " + dp.getApellido1() + " " + dp.getApellido2());
                }
                }
                catch(Exception e)
                {
                System.out.println(e.toString());
                }
                }
                }
                ----------- END OF TEST CLASS --------------

                I have tried to put out of the code everything but the classes needed to reproduce the situation.

                I hope you can see anything I missing to do so.

                Thank you very much.

                Regards,
                Victor

                • 5. Re: Error in JBoss with a BMP EJB

                  One obvious problem I didn't notice in your
                  previous post.

                  if (this.idPaciente == null && this.codCip == null && this.secPaciente == null)
                  code = (new Long(System.currentTimeMillis())).hashCode();

                  Your hashCode will change at random when the key
                  fields are null?

                  You haven't included the database schema (I can
                  probably guess that) or the test data?

                  Regards,
                  Adrian

                  • 6. Re: Error in JBoss with a BMP EJB
                    vicrh

                    Hello Adrian,

                    Thank you very much for your answer.

                    You are right about the problem with my hashCode method. I put that code there because when deploying the EJB, that method got invoked twice with its attributes set to null, so it launched a NullPointerException.

                    I just wanted to prevent that situation, but I forgot the value returned by hashCode has to be the same for all the life of the class' instance.

                    I have changed it so it returns always the same value when all the attributes are null:

                    ------------- BEGINNING OF HASHCODE METHOD ------------
                    public int hashCode() {
                    int code;

                    if (this.idPaciente == null && this.codCip == null && this.secPaciente == null) {
                    System.out.println("ATTENTION: INVOKING hashCode with NULL attributes ...");
                    code = this.getClass().hashCode();
                    }
                    else {
                    code = 0;
                    if (this.idPaciente != null)
                    code += this.idPaciente.hashCode();
                    if (this.codCip != null)
                    code += this.codCip.hashCode();
                    if (this.secPaciente != null)
                    code += this.secPaciente.hashCode();
                    }
                    return code;
                    }
                    ------------- END OF HASHCODE METHOD ------------

                    However, fixing this bug has not solved my problem with JBoss.

                    I'm working with Oracle 8i 8.1.7 database, and using JDBC 2 drivers (classes12.zip). Here are the tables and the data you need to reproduce the error:

                    ------------ BEGINNING OF SQL CODE ----------------
                    drop table TA_TARJETAS;
                    create table TA_TARJETAS (
                    COD_CIP varchar(16) not null,
                    NUM_NASS varchar(12),
                    COD_SEXO varchar(1),
                    DES_NOMBRE varchar(22),
                    DES_APELLIDO1 varchar(22),
                    FEC_NACIMIENTO DATE,
                    COD_DNI_NIE varchar(9),
                    DES_APELLIDO2 varchar(22),
                    DES_DIRECCION varchar(60),
                    COD_POSTAL number(5,0),
                    NUM_TELEF_PPAL number(11,0));

                    alter table TA_TARJETAS add primary key (COD_CIP);

                    insert into TA_TARJETAS values ('tacode1', 'tanass1', 'V', 'taname1', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname1', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode2', 'tanass2', 'M', 'taname2', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname2', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode3', 'tanass3', 'V', 'taname3', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname3', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode4', 'tanass4', 'M', 'taname4', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname4', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode5', 'tanass5', 'V', 'taname5', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname5', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode6', 'tanass6', 'M', 'taname6', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname6', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode7', 'tanass7', 'V', 'taname7', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname7', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode8', 'tanass8', 'M', 'taname8', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname8', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode9', 'tanass9', 'V', 'taname9', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname9', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode10', 'tanass10', 'M', 'taname10', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname10', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode11', 'tanass11', 'V', 'taname11', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname11', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode12', 'tanass12', 'M', 'taname12', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname12', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode13', 'tanass13', 'V', 'taname13', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname13', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode14', 'tanass14', 'M', 'taname14', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname14', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode15', 'tanass15', 'V', 'taname15', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname15', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode16', 'tanass16', 'V', 'taname16', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname16', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode17', 'tanass17', 'M', 'taname17', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname17', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode18', 'tanass18', 'V', 'taname18', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname18', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode19', 'tanass19', 'M', 'taname19', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname19', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode20', 'tanass20', 'V', 'taname20', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname20', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode21', 'tanass21', 'M', 'taname21', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname21', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode22', 'tanass22', 'V', 'taname22', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname22', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode23', 'tanass23', 'M', 'taname23', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname23', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode24', 'tanass24', 'V', 'taname24', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname24', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode25', 'tanass25', 'M', 'taname25', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname25', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode26', 'tanass26', 'V', 'taname26', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname26', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode27', 'tanass27', 'M', 'taname27', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname27', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode28', 'tanass28', 'V', 'taname28', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname28', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode29', 'tanass29', 'M', 'taname29', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname29', 'test street', 123, 123456);
                    insert into TA_TARJETAS values ('tacode30', 'tanass30', 'V', 'taname30', 'DIAZ', TO_DATE('12-11-2002', 'DD-MM-YYYY'), '111111', 'ta2ndsurname30', 'test street', 123, 123456);

                    drop table CC_PACIENTES;
                    create table CC_PACIENTES (
                    SEC_PACIENTE number(10,0) not null,
                    APELLIDO1 varchar(22),
                    APELLIDO2 varchar(22),
                    NOMBRE varchar(22),
                    FEC_NACIMIENTO DATE,
                    SEXO varchar(1),
                    NUM_SS varchar(12),
                    DIRECCION varchar(60),
                    COD_POSTAL varchar(5),
                    DNI varchar(9),
                    NUM_TELF1 varchar(15),
                    TAR_COD_CIP varchar(16));

                    alter table CC_PACIENTES add primary key (SEC_PACIENTE);

                    insert into CC_PACIENTES VALUES (1, 'DIAZ', 'cc2ndsurname1', 'ccname1', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss1', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (2, 'DIAZ', 'cc2ndsurname2', 'ccname2', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss2', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (3, 'DIAZ', 'cc2ndsurname3', 'ccname3', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss3', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (4, 'DIAZ', 'cc2ndsurname4', 'ccname4', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss4', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (5, 'DIAZ', 'cc2ndsurname5', 'ccname5', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss5', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (6, 'DIAZ', 'cc2ndsurname6', 'ccname6', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss6', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (7, 'DIAZ', 'cc2ndsurname7', 'ccname7', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss7', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (8, 'DIAZ', 'cc2ndsurname8', 'ccname8', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss8', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (9, 'DIAZ', 'cc2ndsurname9', 'ccname9', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss9', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (10, 'DIAZ', 'cc2ndsurname10', 'ccname10', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss10', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (11, 'DIAZ', 'cc2ndsurname11', 'ccname11', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss11', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (12, 'DIAZ', 'cc2ndsurname12', 'ccname12', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss12', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (13, 'DIAZ', 'cc2ndsurname13', 'ccname13', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss13', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (14, 'DIAZ', 'cc2ndsurname14', 'ccname14', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss14', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (15, 'DIAZ', 'cc2ndsurname15', 'ccname15', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss15', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (16, 'DIAZ', 'cc2ndsurname16', 'ccname16', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss16', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (17, 'DIAZ', 'cc2ndsurname17', 'ccname17', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss17', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (18, 'DIAZ', 'cc2ndsurname18', 'ccname18', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss18', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (19, 'DIAZ', 'cc2ndsurname19', 'ccname19', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss19', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (20, 'DIAZ', 'cc2ndsurname20', 'ccname20', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss20', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (21, 'DIAZ', 'cc2ndsurname21', 'ccname21', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss21', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (22, 'DIAZ', 'cc2ndsurname22', 'ccname22', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss22', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (23, 'DIAZ', 'cc2ndsurname23', 'ccname23', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss23', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (24, 'DIAZ', 'cc2ndsurname24', 'ccname24', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss24', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (25, 'DIAZ', 'cc2ndsurname25', 'ccname25', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss25', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (26, 'DIAZ', 'cc2ndsurname26', 'ccname26', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss26', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (27, 'DIAZ', 'cc2ndsurname27', 'ccname27', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss27', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (28, 'DIAZ', 'cc2ndsurname28', 'ccname28', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss28', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (29, 'DIAZ', 'cc2ndsurname29', 'ccname29', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss29', 'test street', '123', '111111', '123456', null);
                    insert into CC_PACIENTES VALUES (30, 'DIAZ', 'cc2ndsurname30', 'ccname30', TO_DATE('12-11-2002', 'DD-MM-YYYY'), 'V', 'ccnumss30', 'test street', '123', '111111', '123456', null);

                    drop table RACPPACIENTES;
                    create table RACPPACIENTES (
                    IDPACIENTE number(11,0) not null,
                    NTARJETASANITARIA varchar(16),
                    SEC_PACIENTE number(10,0));

                    alter table RACPPACIENTES add primary key (IDPACIENTE);

                    drop table TA_APELLIDOS_COMUNES;
                    create table TA_APELLIDOS_COMUNES (
                    CODIGO NUMBER(22,0) not null,
                    DES_APELLIDO1 VARCHAR(22),
                    DES_APELLIDO2 VARCHAR(22),
                    CUENTA NUMBER(22,0));

                    alter table TA_APELLIDOS_COMUNES add primary key (CODIGO);
                    ------------ END OF SQL CODE ----------------

                    There is no need for data for the last two tables, but they do have to exist. And here is how I configured the Oracle data source under JBoss:

                    ---------- BEGINNING OF renal-db.service.xml ------------
                    <?xml version="1.0" encoding="UTF-8"?>






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


                    RenalDB


                    <config-property name="ConnectionURL" type="java.lang.String">jdbc:oracle:thin:@10.81.202.10:1521:renal</config-property>
                    <config-property name="DriverClass" type="java.lang.String">oracle.jdbc.driver.OracleDriver</config-property>
                    <config-property name="UserName" type="java.lang.String">renal</config-property>
                    <config-property name="Password" type="java.lang.String">renal</config-property>



                    <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
                    ByContainer


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

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

                    java:/TransactionManager

                    jboss.jca:service=RARDeployer





                    ---------- END OF renal-db.service.xml ------------

                    Well, I hope you can reproduce the problem I'm having with JBoss.

                    Thank you very much for your help.

                    Regards,
                    Victor

                    • 7. Re: Error in JBoss with a BMP EJB
                      vicrh

                      Hello again, Adrian,

                      Finally I have come to solve my problem with JBoss.

                      Having numbered the sample data I got the test program always stalled after retrieving person number 19 from the second table (CC_PACIENTES).

                      While I was pasting you the datasource configuration, I saw that the parameter "MaxSize" for the datasource connection pool "JBossManagedConnectionPool" was set to 50, and that value let me think about the test program stalling after retrieving 30 people from the first table and 19 from the second.

                      I raised that number and now everything works fine. I have set now a value of 500 for "MaxSize" attribute. I was getting confused by the message, but the real problem was that the connection pool was running out of connections. Do you agree with me?

                      Thank you for your help.

                      Regards,
                      Víctor

                      • 8. Re: Error in JBoss with a BMP EJB

                        Did you try changing the PK to not use the time?
                        Maybe it would report the real error with change?

                        Regards,
                        Adrian

                        • 9. Re: Error in JBoss with a BMP EJB
                          vicrh

                          Hello Adrian,

                          Yes, as you can see above I changed the hashCode method of the primary key class so it returned a constant value when all the attributes are null.

                          But the problem continued until I raised the number of connections available in the datasource's connection pool. What confused me was the error returned by JBoss, since it didn't say anything about connections running out in the pool.

                          Is this the normal behaviour?

                          Thank you for your help.

                          Regards,
                          Victor

                          • 10. Re: Error in JBoss with a BMP EJB

                            If your primary key is implemented correctly and
                            you are still seeing this error, it is
                            a bug in the error reporting.

                            If your hashCode() can change value during an invocation
                            then your primary key class is wrong.

                            Regards,
                            Adrian

                            • 11. Re: Error in JBoss with a BMP EJB
                              vicrh

                              Hello Adrian,

                              I think now my primary key class is working fine, as the problem with the hashCode method was fixed and the equals method is working well too.

                              Here is again the code for my primary key class if you wish to check it again, but hopefully you'll find it ok.

                              -------- BEGINNING OF PRIMARY KEY CLASS -------
                              package ejb.test;

                              import java.io.Serializable;

                              /**
                              *
                              * @author Vctor Rodrguez Herreros
                              */
                              public class PacientesPK implements Serializable {
                              protected Long idPaciente;
                              protected String codCip;
                              protected Long secPaciente;

                              /** Creates a new instance of PacientesPK */
                              public PacientesPK() {
                              this.idPaciente = null;
                              this.codCip = null;
                              this.secPaciente = null;
                              }

                              public PacientesPK(Long l) {
                              this.idPaciente = l;
                              this.codCip = null;
                              this.secPaciente = null;
                              }

                              public PacientesPK(Long l1, String s, Long l2) {
                              this.idPaciente = l1;
                              this.codCip = s;
                              this.secPaciente = l2;
                              }

                              public Long getIdPaciente() {
                              return idPaciente;
                              }

                              public void setIdPaciente(Long l) {
                              this.idPaciente = l;
                              }

                              public String getCodCip() {
                              return codCip;
                              }

                              public void setCodCip(String s) {
                              this.codCip = s;
                              }

                              public Long getSecPaciente() {
                              return secPaciente;
                              }

                              public void setSecPaciente(Long l) {
                              this.secPaciente = l;
                              }

                              public boolean equals(Object obj) {
                              boolean result = false;

                              if (obj != null && obj instanceof PacientesPK) {
                              PacientesPK otro = (PacientesPK) obj;

                              if (this.idPaciente == null && otro.getIdPaciente() == null && this.codCip == null &&
                              otro.getCodCip() == null && this.secPaciente == null && otro.getSecPaciente() == null)
                              result = true;
                              else if (this.idPaciente != null && otro.getIdPaciente() != null && this.idPaciente.equals(otro.getIdPaciente()))
                              result = true;
                              else if (this.codCip != null && otro.getCodCip() != null && this.codCip.equals(otro.getCodCip()))
                              result = true;
                              else if (this.secPaciente != null && otro.getSecPaciente() != null && this.secPaciente.equals(otro.getSecPaciente()))
                              result = true;
                              }
                              return result;
                              }

                              public int hashCode() {
                              int code;

                              if (this.idPaciente == null && this.codCip == null && this.secPaciente == null)
                              code = this.getClass().hashCode();
                              else {
                              code = 0;
                              if (this.idPaciente != null)
                              code += this.idPaciente.hashCode();
                              if (this.codCip != null)
                              code += this.codCip.hashCode();
                              if (this.secPaciente != null)
                              code += this.secPaciente.hashCode();
                              }
                              return code;
                              }

                              }

                              -------- END OF PRIMARY KEY CLASS -------

                              I agree with you there can be an error reporting bug, as JBoss never informed me about the exhausted connection pool.

                              Regards,
                              Víctor