7 Replies Latest reply on Feb 7, 2002 1:37 PM by gencom

    Problems with Find All.

    gencom

      Hi all, I'm hoping someone has seen this before and already knows the answer. I'm using JBoss 2.4.4 and the
      default HypersonicDB.

      I've created a simple cmb as follows:

      package com.pandaflowers.cmp;

      import java.rmi.RemoteException;
      import java.util.Collection;
      import javax.ejb.FinderException;
      /**
      * Insert the type's description here.
      * Creation date: (06/02/2002 3:40:21 PM)
      * @author:
      */
      public interface UnitHome extends javax.ejb.EJBHome {

      public Unit create(String unitCode) throws javax.ejb.CreateException, java.rmi.RemoteException;

      public Unit findByPrimaryKey(String primaryKey) throws java.rmi.RemoteException, javax.ejb.FinderException;

      public Collection findAll() throws FinderException, RemoteException;

      public Collection findInRange(String start, String end) throws FinderException, RemoteException;
      }

      I've setup the ejb-jar.xml correctly and am able to create, findByPrimaryKey and remove(). BUT I can not get anything except an empty collection from findAll() or findInRange(...);

      My Jaws file looks like:


      java:/DefaultDS
      <type-mapping>Hypersonic SQL</type-mapping>
      false

      <default-entity>
      <create-table>true</create-table>
      <remove-table>false</remove-table>
      <tuned-updates>true</tuned-updates>
      <read-only>false</read-only>
      <time-out>300</time-out>
      <select-for-update>false</select-for-update>
      </default-entity>

      <enterprise-beans>

      <ejb-name>UnitBean</ejb-name>
      <table-name>Unit2</table-name>


      findInRange
      unitCode &#62; &#39;{0}&#39; AND unitCode &#60; &#39;{1}&#39;
      unitCode ASC


      </enterprise-beans>

      <type-mappings>

      Any help would be appreciated!

      Thanks

      -Eric.

        • 1. Re: Problems with Find All.
          armint

          In findInRange, instead of < make sure you use & lt; without any spaces like I have used.

          • 2. Re: Problems with Find All.
            gencom

            Thanks for the advise, but I did!. The act of cutting and pasting it to the list interreted it and showed it as a < rather than a &amp;lt;. Any other ideas?

            -Eric.

            • 3. Re: Problems with Find All.
              armint

              Sorry, that was my only idea. So, if you do a create(unitCode) then findAll() you get an empty collection? What are your transactional attributes?

              • 4. Re: Problems with Find All.
                seven

                try to replace unitCode > '{0}' AND unitCode < '{1}' with unitCode>{0} AND unitCode&lt;{1}. if this still doesn't work try to turn the debbuging on and watch the logs to see what sql statements is jboss running when u call the finders

                • 5. Re: Problems with Find All.
                  ppetit

                  Did you declare your findAll finder within your EJBHome interface ?

                  Philippe

                  • 6. Re: Problems with Find All.
                    gencom

                    Tried all the suggestions and came up with...

                    Transactions fragment is as follows:
                    <container-transaction>

                    <ejb-name>UnitBean</ejb-name>
                    <method-name>*</method-name>

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

                    The output of the log is as follows.

                    [11:18:42,079,AutoDeployer] Auto deploy of file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/deploy/PandaFlowers.ear
                    [11:18:42,081,J2eeDeployer] Deploy J2EE application: file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/deploy/PandaFlowers.ear
                    [11:18:42,097,J2eeDeployer] Create application PandaFlowers.ear
                    [11:18:42,622,J2eeDeployer] install EJB module PandaFlowers.jar
                    [11:18:42,648,J2eeDeployer] add all ejb jar files to the common classpath
                    [11:18:42,658,ContainerFactory] Deploying:file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/tmp/deploy/Default/PandaFlowers.ear
                    [11:18:42,979,ContainerFactory] Verifying file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/tmp/deploy/Default/PandaFlowers.ear/ejb1006.jar
                    [11:18:43,034,ContainerFactory] UnitBean: Verified.
                    [11:18:43,042,ContainerFactory] Deploying UnitBean
                    [11:18:43,059,JRMPContainerInvoker] Container Invoker RMI Port='4444'
                    [11:18:43,059,JRMPContainerInvoker] Container Invoker Client SocketFactory='Default'
                    [11:18:43,059,JRMPContainerInvoker] Container Invoker Server SocketFactory='Default'
                    [11:18:43,060,JRMPContainerInvoker] Container Invoker Server SocketAddr='Default'
                    [11:18:43,060,JRMPContainerInvoker] Container Invoker Server sslDomain='Default'
                    [11:18:43,060,JRMPContainerInvoker] Container Invoker Optimize='true'
                    [11:18:43,062,EntityInstancePool] config - MaximumSize=100, strictMaximumSize=false, feederPolicy=null
                    [11:18:43,063,EntityContainer] Begin java:comp/env for EJB: UnitBean
                    [11:18:43,064,EntityContainer] TCL: java.net.URLClassLoader@40b181
                    [11:18:43,075,EntityContainer] End java:comp/env for EJB: UnitBean
                    [11:18:43,160,JRMPContainerInvoker] JRMP 1.3 CI initialized
                    [11:18:43,161,JAWSPersistenceManager] Initializing JAWS plugin for UnitBean
                    [11:18:43,166,JAWSPersistenceManager] Loading standardjaws.xml : file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/conf/catalina/standardjaws.xml
                    [11:18:43,450,JAWSPersistenceManager] jar:file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/tmp/deploy/Default/PandaFlowers.ear/ejb1006.jar!/META-INF/jaws.xml found. Overriding defaults
                    [11:18:43,539,JAWSPersistenceManager] Init SQL: CREATE TABLE Unit2 (unitCode VARCHAR(256))
                    [11:18:43,539,JAWSPersistenceManager] Destroy SQL: DROP TABLE Unit2
                    [11:18:43,540,JAWSPersistenceManager] Exists SQL: SELECT COUNT(*) FROM Unit2 WHERE unitCode=?
                    [11:18:43,541,JAWSPersistenceManager] findInRange SQL: SELECT Unit2.unitCode FROM Unit2 where unitCode>'?' AND unitCode<'?' ORDER BY unitCode ASC
                    [11:18:43,542,JAWSPersistenceManager] AutoGenerated finders - Home=interface com.pandaflowers.cmp.UnitHome -- LocalHome=null
                    [11:18:43,543,JAWSPersistenceManager] Save AutoGenerated findAll public abstract java.util.Collection com.pandaflowers.cmp.UnitHome.findAll() throws javax.ejb.FinderException,java.rmi.RemoteException
                    [11:18:43,563,JAWSPersistenceManager] findAll SQL: SELECT unitCode FROM Unit2
                    [11:18:43,563,JAWSPersistenceManager] Create SQL: INSERT INTO Unit2 (unitCode) VALUES (?)
                    [11:18:43,575,JAWSPersistenceManager] Remove SQL: DELETE FROM Unit2 WHERE unitCode=?
                    [11:18:43,576,JAWSPersistenceManager] Load SQL: SELECT Unit2.unitCode FROM Unit2 WHERE unitCode=?
                    [11:18:43,576,JAWSPersistenceManager] Load SQL: SELECT Unit2.unitCode FROM Unit2 WHERE unitCode=?
                    [11:18:43,580,JAWSPersistenceManager] Table 'Unit2' already exists
                    [11:18:43,691,JRMPContainerInvoker] Bound UnitBean to UnitBean
                    [11:18:43,714,UnitBean] Initializing
                    [11:18:43,727,UnitBean] Initialized
                    [11:18:43,739,UnitBean] Starting
                    [11:18:43,751,UnitBean] Started
                    [11:18:43,793,ContainerFactory] Deployed application: file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/tmp/deploy/Default/PandaFlowers.ear
                    [11:18:43,814,J2eeDeployer] J2EE application: file:/u/JBoss-2.4.4_Tomcat-4.0.1/jboss/deploy/PandaFlowers.ear is deployed.
                    [11:19:49,392,JAWSPersistenceManager] findAll command executing: SELECT unitCode FROM Unit2
                    [11:19:49,410,JAWSPersistenceManager] Create, id is stem
                    [11:19:49,410,JAWSPersistenceManager] Exists command executing: SELECT COUNT(*) FROM Unit2 WHERE unitCode=?
                    [11:19:49,410,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=stem
                    [11:19:49,413,JAWSPersistenceManager] Create command executing: INSERT INTO Unit2 (unitCode) VALUES (?)
                    [11:19:49,414,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=stem
                    [11:19:49,415,JAWSPersistenceManager] Rows affected = 1
                    [11:19:49,527,JAWSPersistenceManager] Create, id is box
                    [11:19:49,528,JAWSPersistenceManager] Exists command executing: SELECT COUNT(*) FROM Unit2 WHERE unitCode=?
                    [11:19:49,528,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=box
                    [11:19:49,531,JAWSPersistenceManager] Create command executing: INSERT INTO Unit2 (unitCode) VALUES (?)
                    [11:19:49,531,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=box
                    [11:19:49,533,JAWSPersistenceManager] Rows affected = 1
                    [11:19:49,553,JAWSPersistenceManager] Create, id is bunch
                    [11:19:49,554,JAWSPersistenceManager] Exists command executing: SELECT COUNT(*) FROM Unit2 WHERE unitCode=?
                    [11:19:49,554,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=bunch
                    [11:19:49,557,JAWSPersistenceManager] Create command executing: INSERT INTO Unit2 (unitCode) VALUES (?)
                    [11:19:49,557,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=bunch
                    [11:19:49,559,JAWSPersistenceManager] Rows affected = 1
                    [11:19:49,592,JAWSPersistenceManager] findInRange command executing: SELECT Unit2.unitCode FROM Unit2 where unitCode>'?' AND unitCode<'?' ORDER BY unitCode ASC
                    [11:19:49,592,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=a
                    [11:19:49,593,JAWSPersistenceManager] Set parameter: idx=2, jdbcType=VARCHAR, value=z
                    [11:19:55,844,JAWSPersistenceManager] findAll command executing: SELECT unitCode FROM Unit2
                    [11:19:55,862,JAWSPersistenceManager] Create, id is stem
                    [11:19:55,863,JAWSPersistenceManager] Exists command executing: SELECT COUNT(*) FROM Unit2 WHERE unitCode=?
                    [11:19:55,863,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=stem
                    [11:19:55,869,JAWSPersistenceManager] Create command executing: INSERT INTO Unit2 (unitCode) VALUES (?)
                    [11:19:55,869,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=stem
                    [11:19:55,871,JAWSPersistenceManager] Rows affected = 1
                    [11:19:55,873,UnitBean] CONTAINER EXCEPTION:
                    java.lang.IllegalStateException: INSERTING AN ALREADY EXISTING BEAN, ID = stem
                    at org.jboss.ejb.plugins.AbstractInstanceCache.insert(AbstractInstanceCache.java:269)
                    at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:161)
                    at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:97)
                    at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:142)
                    at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:277)
                    at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
                    at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:102)
                    at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:103)
                    at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:421)
                    at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.java:387)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
                    at sun.rmi.transport.Transport$1.run(Transport.java:152)
                    at java.security.AccessController.doPrivileged(Native Method)
                    at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
                    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
                    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
                    at java.lang.Thread.run(Thread.java:484)
                    [11:19:56,238,JAWSPersistenceManager] findInRange command executing: SELECT Unit2.unitCode FROM Unit2 where unitCode>'?' AND unitCode<'?' ORDER BY unitCode ASC
                    [11:19:56,239,JAWSPersistenceManager] Set parameter: idx=1, jdbcType=VARCHAR, value=a
                    [11:19:56,239,JAWSPersistenceManager] Set parameter: idx=2, jdbcType=VARCHAR, value=z

                    Still at a loss with both findAll() and findInRange()

                    - Eric

                    • 7. Re: Problems with Find All.
                      gencom

                      Mystery solved!

                      It appears that I've been mixing my ejb-jar definitions under test and infact the transactional tags were the answer... Thanks! Remove the transactional assembly tags and it all works as expected!