12 Replies Latest reply on Nov 21, 2002 7:06 AM by Schneider

    finder question

    Volkan Yildiz Newbie

      Hi all,
      I want to search field start with something, but how can i use finderMethod argument. For example if my function
      is f(String name),which query can i use. I tried this;

      query="SELECT OBJECT (p) FROM Personnels AS p WHERE
      p.name1 LIKE ?1+'%' "

      ,where name1 my persistent field and Personnels my schema,but it didn't work, normally. But how can i do that.
      Thanks all,

        • 1. Re: finder question
          Tung Dang Novice

          I think you have to cat the wildcard in your argument and then pass it as a normal parameter to your finder method. So it could look like this:

          QUERY: SELECT OBJECT (p) FROM Personnels AS p WHERE
          p.name1 LIKE ?1

          ...
          name1 = "%" + name1 + "%";
          finderMethod(name1)
          ...

          Hope it hepls.

          • 2. Re: finder question
            Volkan Yildiz Newbie

            hi tdang, thans for your idea, i tried that but it has given me the error bellow,

            I think it is angry about " LIKE ?1 " part, and it may expect a string and probably in the form ''. What you think?


            org.jboss.deployment.DeploymentException: Error compiling ejbql; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "1" at line 1, column 59.
            Was expecting:
            <STRING_LITERAL> ...
            )
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.(JDBCEJBQLQuery.java:46)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCCommandFactory.createEJBQLQuery(JDBCCommandFactory.java:44)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.start(JDBCQueryManager.java:214)
            at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.start(JDBCStoreManager.java:389)
            at org.jboss.ejb.plugins.CMPPersistenceManager.start(CMPPersistenceManager.java:198)
            at org.jboss.ejb.EntityContainer.start(EntityContainer.java:376)
            at org.jboss.ejb.Container.invoke(Container.java:793)
            at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:894)
            at $Proxy6.start(Unknown Source)
            at org.jboss.system.ServiceController.start(ServiceController.java:340)
            at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
            at $Proxy4678.start(Unknown Source)
            at org.jboss.ejb.EjbModule.startService(EjbModule.java:440)
            at org.jboss.system.ServiceMBeanSupport.start(ServiceMBeanSupport.java:162)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:894)
            at $Proxy6.start(Unknown Source)
            at org.jboss.system.ServiceController.start(ServiceController.java:340)
            at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
            at $Proxy5.start(Unknown Source)
            at org.jboss.ejb.EJBDeployer.start(EJBDeployer.java:398)
            at org.jboss.deployment.MainDeployer.start(MainDeployer.java:678)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:513)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:481)
            at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
            at $Proxy4.deploy(Unknown Source)
            at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:405)
            at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:515)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:202)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:191)
            Caused by: org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "1" at line 1, column 59.
            Was expecting:
            <STRING_LITERAL> ...

            • 3. Re: finder question
              Tin Blaskovic Newbie

              It's beacuse you're using EJB-QL. Use JBoss-QL (define your query inside <jboss-ql> tags (in jbosscmp-jdbc.xml), leave the <ejb-ql> query tag in ejb-jar.xml empty.

              • 4. Re: finder question
                Volkan Yildiz Newbie

                I'm usung XDoclet and i tried to write this, but it did not work.

                I wrote;
                * @jboss:finder-query name="findName1"
                * query="name1 LIKE {1} "
                * order = "name1"
                * @ejb:finder signature="java.util.Collection
                findName1(java.lang.String name)"
                * result-type-mapping="Local"

                Any idea?Regards...

                • 5. Re: finder question
                  Arno Huetter Newbie

                  Hello,

                  AFAIK the LIKE operator cannot be used with input parameters (at least that's what's being stated in Monson-Haefel's "Enterprise JavaBeans" book, 3rd ed.). You can only hardcode your comparison patterns.

                  Kind regards,
                  Arno Huetter

                  • 6. Re: finder question
                    Tin Blaskovic Newbie


                    Yes, that's why ejbql doesn't support it in JBoss, but jbossql does. I've written an example in one of these forums, but since the search doesn't seem to work:

                    @ejb:finder signature="java.util.Collection findName1(java.lang.String name)"
                    result-type-mapping="Local"
                    @jboss:query signature="java.util.Collection findName1(java.lang.String name)"
                    query="select object(s) from schemaname s where s.name1 like ?1"

                    Don't forget to set your schema in the @ejb:bean xdoclet tag. BTW, this will work in xdoclet 1.2, not sure about 1.1.

                    • 7. Re: finder question
                      Volkan Yildiz Newbie

                      Hi canobi,
                      Are u sure about the jboss query,i got the following error.Something wrong but i could not find.
                      it is my code:

                      * @ejb:bean name="MyEntity"
                      * display-name="MyEntity name"
                      * type="CMP"
                      * jndi-name="my jndi-name"
                      * schema = "Personnels"
                      *
                      *
                      * @ejb:ejb-ref ejb-name="my ejb-name"
                      *
                      * @ejb:transaction type="Required"
                      *
                      * @jboss:table-name table-name="PERSONNEL"
                      *
                      * @ejb:data-object extends="com.bs4c.util.interfaces.AbstractData"
                      * setdata="false"
                      *
                      * @ejb:finder signature="java.util.Collection findAll()"
                      *
                      * @ejb:finder signature="java.util.Collection findName1( java.lang.String name)"
                      * result-type-mapping="Local"
                      *
                      * @jboss:query signature="java.util.Collection findName1(java.lang.String name)"
                      * query="select object(s) from Personnels as s where s.name1 like ?1"
                      *


                      //------------------ERROR--------------------------------

                      11:56:31,329 INFO [MainDeployer] Successfully completed deployment of package: file:/usr/local/jboss/jboss-3.0.0/server/default/deploy/ejb-bs4c.jar
                      11:56:36,607 ERROR [STDERR] javax.ejb.FinderException: Unknown query: public abstract java.util.Collection com.bs4c.personnel.interfaces.PersonnelEntityHome.findName1(java.lang.String) throws java.rmi.RemoteException,javax.ejb.FinderException
                      11:56:36,609 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.getQueryCommand(JDBCQueryManager.java:56)
                      11:56:36,609 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntitiesCommand.execute(JDBCFindEntitiesCommand.java:38)
                      11:56:36,609 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.findEntities(JDBCStoreManager.java:472)
                      11:56:36,610 ERROR [STDERR] at org.jboss.ejb.plugins.CMPPersistenceManager.findEntities(CMPPersistenceManager.java:348)
                      11:56:36,610 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntities(CachedConnectionInterceptor.java:323)
                      11:56:36,610 ERROR [STDERR] at org.jboss.ejb.EntityContainer.find(EntityContainer.java:662)
                      11:56:36,610 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      11:56:36,610 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                      • 8. Re: finder question
                        Volkan Yildiz Newbie

                        Hi canobi,
                        Are u sure about the jboss query,i got the following error.Something wrong but i could not find.
                        it is my code:

                        * @ejb:bean name="MyEntity"
                        * display-name="MyEntity name"
                        * type="CMP"
                        * jndi-name="my jndi-name"
                        * schema = "Personnels"
                        *
                        *
                        * @ejb:ejb-ref ejb-name="my ejb-name"
                        *
                        * @ejb:transaction type="Required"
                        *
                        * @jboss:table-name table-name="PERSONNEL"
                        *
                        * @ejb:finder signature="java.util.Collection findAll()"
                        *
                        * @ejb:finder signature="java.util.Collection findName1( java.lang.String name)"
                        * result-type-mapping="Local"
                        *
                        * @jboss:query signature="java.util.Collection findName1(java.lang.String name)"
                        * query="select object(s) from Personnels as s where s.name1 like ?1"
                        *


                        //------------------ERROR--------------------------------

                        11:56:31,329 INFO [MainDeployer] Successfully completed deployment of package: file:/usr/local/jboss/jboss-3.0.0/server/default/deploy/ejb-bs4c.jar
                        11:56:36,607 ERROR [STDERR] javax.ejb.FinderException: Unknown query: public abstract java.util.Collection com.bs4c.personnel.interfaces.PersonnelEntityHome.findName1(java.lang.String) throws java.rmi.RemoteException,javax.ejb.FinderException
                        11:56:36,609 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCQueryManager.getQueryCommand(JDBCQueryManager.java:56)
                        11:56:36,609 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntitiesCommand.execute(JDBCFindEntitiesCommand.java:38)
                        11:56:36,609 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.findEntities(JDBCStoreManager.java:472)
                        11:56:36,610 ERROR [STDERR] at org.jboss.ejb.plugins.CMPPersistenceManager.findEntities(CMPPersistenceManager.java:348)
                        11:56:36,610 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntities(CachedConnectionInterceptor.java:323)
                        11:56:36,610 ERROR [STDERR] at org.jboss.ejb.EntityContainer.find(EntityContainer.java:662)
                        11:56:36,610 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                        11:56:36,610 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                        • 9. Re: finder question
                          Tin Blaskovic Newbie

                          Well, I forgot about an empty query. You need this to let the server know there is a query defined, but to look for it elsewhere. So, your ejb:finder must look something like this:
                          @ejb:finder signature="something"
                          result-type-mapping="Local"
                          query=""
                          That should do it.

                          • 10. Re: finder question
                            Renato Newbie

                            canobi,

                            I trying to get that finder to run too. So I looked at your samples.

                            According to xDoclet 1.1.2:
                            @jboss:query --> SHOULD BE @jboss:finder-query

                            Deployment in JBoss 3.0.4
                            @ejb:finder ... query="" --> Empty query does not deploy

                            Since you have a working example, would you please post your whole Bean Header and state also what version of JBoss, xDoclet, and Database you are using.

                            Thanks a lot

                            • 11. Re: finder question
                              Tin Blaskovic Newbie


                              This example is for xdoclet 1.2. I said I was not sure if it worked in 1.1, now I can see it doesn't :-) My setup is ant 1.5, xdoclet 1.2 and jboss 3.0.3 with sap-db and the example works there. I think xdoclet 1.1.2 is horribly outdated where jboss is concerned by now, and even though 1.2 is beta it works for me without any problems.

                              • 12. Re: finder question
                                Schneider Newbie

                                hello!

                                i had the same problem, and after a lot of test i solved it.
                                the following should work:

                                * @ejb.bean name="aum/Contact"
                                * display-name="represents a Contact"
                                * type="CMP"
                                * jndi-name="ejb/aum/Contact"
                                * view-type="both"
                                * schema="aumContact"

                                * @ejb:finder signature="java.util.Collection findByNickNamePattern(java.lang.String nickName)"
                                * query="SELECT OBJECT(c) FROM aumContact AS c"
                                * @jboss.query signature="java.util.Collection findByNickNamePattern(java.lang.String nickName)"
                                * query="SELECT OBJECT(c) FROM aumContact AS c WHERE c.nickName LIKE ?1"

                                greetings,
                                rudi