Using wildcards in custom find methods with CMP beans

Hi,
I'd like to create a custom find method called findByName which accepts a string. I'd typically want to use the string in a '%<name>%' scenario, where the user needn't type in the whole name. Does anybody know what the partial query should look like? I'm not sure how to concatenate the '%' symbol to the string taken in.
Thanks in advance
Gillian

Gillian-
Bind variables are of the form $1, $2, etc., so try using a query stmt like this:
select * from YOURTABLE where name like '%$1%'
Regards,
-Jon

Similar Messages

  • Finder methods for CMP beans

    We do not implement finder method in Bean class for CMP. As such, where do we implement finder methods such as findInRange() method? How does the container implement my custom "find" methods.
    Thanks

    Using CMP 2.x, your custom finder and select methods are implemented by the container based on the EJB QL query you provide in the ejb-jar.xml. In CMP 1.1, there was no portable way to express the semantics of the query, so most vendors had a vendor-specific syntax for describing the query.
    See chapter 27 of the J2EE 1.4 Tutorial for some examples of using EJB QL :
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html
    --ken
    Kenneth Saks
    J2EE SDK Team
    SUN Microsystems

  • Binary Data Type in finder methods for CMP beans

    How to write an equivalent ejb-ql query in ejb-jar.xml for a finder method accepting
    a byte array as a parameter. The finder method is for a cmp-field mapped to a
    database field with binary data type

    Using CMP 2.x, your custom finder and select methods are implemented by the container based on the EJB QL query you provide in the ejb-jar.xml. In CMP 1.1, there was no portable way to express the semantics of the query, so most vendors had a vendor-specific syntax for describing the query.
    See chapter 27 of the J2EE 1.4 Tutorial for some examples of using EJB QL :
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html
    --ken
    Kenneth Saks
    J2EE SDK Team
    SUN Microsystems

  • CMP Custom Finder Method Problem

    Hi everybody,
    I have a problem about CMP Custom Finder Method.
    I made CMP Entity Bean and deployed.
    Then, I updated finder section in orion-ejb-jar.xml to add my custom finder query.
    Here is updating finder section in my orion-ejb-jar.xml.
    <finder-method query="(($schStartDate &lt;= TO_DATE($1,'MM-DD-YYYY a HH:MI') and $schEndDate &gt;= TO_DATE($1,'MM-DD-YYYY a HH:MI')) or ($schStartDate &lt;= TO_DATE($2,'MM-DD-YYYY a HH:MI') and $schEndDate &gt;= TO_DATE($2,'MM-DD-YYYY a HH:MI'))) and ($schRoom = $3)">
    <!-- Generated SQL: "......" -->
    <method>
    <ejb-name>RoomSchedule</ejb-name>
    <method-name>findBySchDateAndRoom</method-name>
    <method-params>
    <method-param>java.lang.String</method-param>
    <method-param>java.lang.String</method-param>
    <method-param>java.lang.String</method-param>
    </method-params>
    </method>
    </finder-method>
    <resource-ref-mapping name="jdbc/OracleDS" />
    And, i restarted oc4j. so, oc4j redepoyed CMP bean.
    But, when my client program called CMP Bean, lookup() was ok, but calling findBySchDateAndRoom() was bad.
    I couldn't get any result collection.
    Here is my client code.
    Context ctx = new InitialContext();
    Object ref = ctx.lookup("RoomSchedule");
    roomScheduleHome = (RoomScheduleHome) PortableRemoteObject.narrow(ref, RoomScheduleHome.class);
    String startDT = new String("07-30-2002 am 10:30");
    String endDT = new String("07-30-2002 pm 05:20);
    String roomID = "TEST";
    Collection roomAllSch = roomScheduleHome.findBySchDateAndRoom(startDT, endDT, roomID1);
    Iterator roomSchItr = roomAllSch.iterator();
    int schQty = 0;
    while (roomSchItr.hasNext()) {
    roomSchedule = (RoomSchedule) roomSchItr.next();
    if(roomSchedule.getStatus().equals("A"))
    schQty++;
    After excuting above code, schQty was still zero!!
    Because Collection roomAllSch had not any items.
    But, table ROOMSCHEDULE had 30 records which were same query condition in my database.
    I traced SQL statement using P6Spy Class.
    Here is spy.log.
    1028006337814|10|0|statement|select * from RoomSchedule where ((RoomSchedule.schStartDate <= TO_DATE(?,'MM-DD-YYYY A.M. HH:MI') and RoomSchedule.schEndDate >= TO_DATE(?,'MM-DD-YYYY A.M. HH:MI')) or (RoomSchedule.schStartDate <= TO_DATE(?,'MM-DD-YYYY A.M. HH:MI') and RoomSchedule.schEndDate >= TO_DATE(?,'MM-DD-YYYY A.M. HH:MI'))) and (RoomSchedule.schRoom = ?)|select * from RoomSchedule where ((RoomSchedule.schStartDate <= TO_DATE('7-30-2002 ?@@| 01:00','MM-DD-YYYY A.M. HH:MI') and RoomSchedule.schEndDate >= TO_DATE('7-30-2002 ?@@| 01:00','MM-DD-YYYY A.M. HH:MI')) or (RoomSchedule.schStartDate <= TO_DATE('7-30-2002 ?@HD 12:00','MM-DD-YYYY A.M. HH:MI') and RoomSchedule.schEndDate >= TO_DATE('7-30-2002 ?@HD 12:00','MM-DD-YYYY A.M. HH:MI'))) and (RoomSchedule.schRoom = 'Earth')
    1028006337824|10|0|statement|select RoomSchedule.schTitle, RoomSchedule.schStartDate, RoomSchedule.schEndDate, RoomSchedule.schDayAll, RoomSchedule.status, RoomSchedule.schRoom, RoomSchedule.reqUser, RoomSchedule.apprUser, RoomSchedule.purpose, RoomSchedule.relatoinID, RoomSchedule.schDesc, RoomSchedule.reqDate, RoomSchedule.apprDate from RoomSchedule where (RoomSchedule.schID = ?)|select RoomSchedule.schTitle, RoomSchedule.schStartDate, RoomSchedule.schEndDate, RoomSchedule.schDayAll, RoomSchedule.status, RoomSchedule.schRoom, RoomSchedule.reqUser, RoomSchedule.apprUser, RoomSchedule.purpose, RoomSchedule.relatoinID, RoomSchedule.schDesc, RoomSchedule.reqDate, RoomSchedule.apprDate from RoomSchedule where (RoomSchedule.schID = 0)
    As you see it, two query statement were executed.
    First query statement was ok and got some result records.
    But, second query statement was bad so didn't get any result records.
    I didn't understand why second query statement was executed.
    When roomAllSch.iterator() was being excuted in my client program, second query statment was executed.
    I couldn't believe....
    What's wrong? Please help me....
    OC4J : Version 9 Release 2
    Database : Oracle 8i
    OS : Windows 2000 Professional

    I created CMP of EJB 1.1, I wanted to add a finder
    there, but it didn't work.
    the error message is:
    "AccountEJB_vkbo0d_HomeImpl.java":
    AccountEJB_vkbo0d_HomeImpl should be declared
    abstract; it does not define findBySalary(float) in
    AccountEJB_vkbo0d_HomeImpl at line 11, column 1I think I don't remember CMPs having finder methods anything other than abstract. The code goes in the deployment descriptor. I hope you atleast got that right.
    Richard.

  • Custom finder methods

    I'm tring to deploy an Entity bean (CMP) with custom finder method that gets a parameter.
    I encountered two problems :
    1) defining the query in the deployment descriptor coased the app server to generate the a query without the where cloase - this was fixed by changing manualy the orion-ejb-jar.xml in the application-deployments directory.
    2)the second, and yet unresolved problem, is that OC4J doesn't bind the parameter that the query uses during runtime. I'm recieving an ORA msg that claims that not all the parameters are binded.

    see sample code
    http://otn.oracle.com/sample_code/tech/java/oc4j/htdocs/oc4jsamplecode/oc4j-demo-ejb.html
    also there should be a section in our documentation about cmp custom finder methods. oc4j attempts to generate custome finder methods based on home interface
    <finder-method query="$empNo = $1">
    <method>
                             <ejb-name>EmployeeBean</ejb-name>
                             <method-name>findByEmpNo</method-name>
                             <method-params>
                                  <method-param>java.lang.Integer</method-param>
                             </method-params>
                        </method>
                   </finder-method>

  • Configuring Lazy Loading on Finder Methods with Annotations

    Hi!
    I would like to ask you if it is possible to "Configuring Lazy Loading on Finder Methods with Annotations" in Toplink Essentials, using annotations instead of deployment descriptor.
    Thank you,
    Florin

    I am not sure what you are asking. Lazy loading is configured on the mapping, not the queries.
    There are examples on how to configure lazy loading on mappings at www.otn.oracle.com/jpa. If this is not what youare trying to do, please give me a use case that you are trying to support. thanks
    Peter

  • Partial queries with CMP beans

    Hi,
    I have a custom finder method called findBySurname which takes in a string. I've set up the partial query to read: surname=$1 (where surname is the cmp field mapped to the table column). I've checked the orion-ejb-jar.xml file and the query has been inserted. However, when I run the sample client, I get a resultset that contains all the records in the table! I've got similar finder methods on 3 CMP beans and they all do the same thing. Is this a bug in the Release Candidate 2 version of Jdeveloper (which I'm using) or am I missing something?
    Thanks in advance,
    Gillian

    Known Issues along with the bug # are documented in the release notes of the product.
    You can see the release notes from Help menu of the product.
    raghu
    JDev Team

  • Finder  method in Entity bean

    how many Finder method in Entity bean i can write ?
    look below...
    public Account findByPrimaryKey(AccountPK key) throws FinderException,
    RemoteException;
    public Enumeration findByOwnerName(String name) throws FinderException,
    RemoteException;here 2 finder methods are there.......i am asking how much freedom i have ? can write as many as finder method i wish ?
    say, findXXXX() ?

    my problem is on the signature of the find
    method.
    OK let me ask you some other way.
    java DOC says
    Each enterprise Bean has a home interface. The home
    interface must extend the javax.ejb.EJBHome
    interface, and define the enterprise Bean type
    specific create and finder methods (session Beans do
    not have finders).
    look it says " finder methods "....right .
    so i want to ask 2 question about this phrase . PLZ
    do confirm me whether i am right or wrong.
    fact 1. finder methods means you can write
    any method name which starts with word find
    and ONLY find
    Example: findABCD( ) , findEFGH(),
    findBLAHBLAH()...any thing starts with find[i]
    are called finder methods...others are NOT.
    is This fact correct ?
    Yes.
    fact 2. Is not it Strange that i need to
    append some letters after the word find to
    get a finder method name !! why not wrting a simple
    method name ( say abcdfgrty () instead of
    findXXXX() which will do the job ??You can... but it has to be called form a findXXXX() method :)
    As such there is no problem in writng a
    find_ANY_WORDS_HERE() to get a finder method but
    problem is why i need to stick to the word
    find and append some words after it
    t to get a finder method ? if i had to do it
    seriously then whats the role of the container ? how
    w it is linking ?Once someone takes the pain of going through the EJB specs, he would not have a problem. Imagine each vendor using his own brains and the developer getting bugged with new features in each AS. EJB specs are flexible enough already :)

  • Handling BLOBs with CMP Beans

    Hi,
    is there a detailed example how to handle Blob's with CMP Beans?
    I'm trying to store some images in a database (Oracle 9i) using CMP Beans and Oracle iAS 9.03 and jdk 1.4.
    Thanks in advance
    Jens

    We are currently developing a How-To on this and will put this on OTN.
    1) Code snippet from Bean Class:
    public abstract byte[] getPicture();
    public abstract void setPicture(byte[] newPicture);
    public Long ejbCreate(Long empno, byte[] newPicture)
    setEmpno(empno);
    setPicture(newPicture);
    return empno;
    public void ejbPostCreate(Long empno, byte[] newPicture)
    2) Mapping in the orion-ejb-jar.xml:
    <entity-deployment name="EmployeePicture" data-source="jdbc/OracleDS" table="EMPPIC">
    <primkey-mapping>
    <cmp-field-mapping name="empno" persistence-name="EMPNO" persistence-type="NUMBER(8)"/>
    </primkey-mapping>
    <cmp-field-mapping name="empno" persistence-name="EMPNO" persistence-type="NUMBER(8)"/>
    <cmp-field-mapping name="picture" persistence-name="PICTURE" persistence-type="BLOB(4000)"/>
    </entity-deployment>
    3) Create the client to create the bean:
    Long empNo =(Long) Long.valueOf(request.getParameter("EmpNo"));
    String fileName =request.getParameter("ImageFileName");
    InputStream is = new BufferedInputStream(new FileInputStream(fileName));
    int len;
    // Initialize byte array
    byte byteValue[] = new byte[2048000];
    len = is.read(byteValue);
    EmployeePictureLocal employeePicture = empHome.create(empNo , byteValue);
    out.println("Picture of Emp#:"+empNo +" successfully Loaded into DB <br> <br>");
    4) Code snippet to view the image :
    Long empNo =(Long) Long.valueOf(request.getParameter("EmpNo"));
    out.println("Picture of Emp#"+empNo);
    EmployeePictureLocal emp = empHome.findByPrimaryKey(empNo);
    response.setContentType("image/jpeg");
    OutputStream os = null;
    os = response.getOutputStream() ;
    byte[] pic = emp.getPicture();
         os.write(pic);
    os.close();
    os = null;
    Let me know if this helps
    thanks
    Debu

  • How to implement find methods in CMP?

    As OC4J does not support EJB-QL, we need to implement the find methods by ourselves. But how? Here is my thought.
    1) Still declare the find methods in EJB home, such as
    public Collection findBySponsor(String sponsorGuid);
    2) Do not add query part to ejb-jar.xml file;
    3) In the bean class, implement the find method using JDBC code.
    Does CMP allows explicit-implementation of finder methds?
    Does CMP allows explicit-call to JDBC code?
    Thanks,

    Henry -- Why go to that trouble? For the near term I would suggest that you just modify the generated
    orion-ejb-jar.xml descriptors which will include tags to allow you to either 1) enter a partial criteria or
    2) enter a complete SQL statement. This is much less work and when EJB-QL is available with the product,
    then you have to only add the EJB-QL to the ejb-jar.xml.
    Thanks -- Jeff

  • Find method with dates

    Hellow ,
    I want to create a find-method that should represent following statement :
    select * from emp where date > to_date( '24/01/2002', 'dd/MM/yyyy' );
    I defined in my EJB-home-method something like this ...
    public Collection findByStukEname( String date ) throws RemoteException, FinderException;
    Then I deployed to a J2ee-server ...
    and in the orion-ejb-jar.xml I changed the finder-method into ...
    <finder-method query="select * from emp where date > to_date( $1 , 'dd/MM/yyyy' )" partial="false">
    <method>
    <ejb-name>EMP</ejb-name>
    <method-name>findByStukEname</method-name>
    <method-params>
    <method-param>java.lang.String</method-param>
    </method>
    </finder-method>
    But i doesn't work ? Did I make a mistake ?? Is there a beter way to do it ?? ( maybe working with java.util.Date ?? )
    Greetz
    Steven

    Hi Steven,
    OC4J uses an instance of java.sql.PreparedStatement to execute your
    "finder" method. Now you have defined a member of your bean class that will be inserted into your query string in place of the "$1".
    I'm guessing that this member is an instance of "Date" (either
    java.util.Date or java.sql.Date). If that is the case, then you need
    to change your query string to
    select * from emp where date > $1
    Also, you may not be aware of this, but I always use java.sql.Timestamp
    when mapping EJB members to DATE columns in the Oracle database tables.
    (Not java.sql.Date)
    Hope this helps,
    Avi.

  • How implement finder method with bean inheritance?

    I have a ProductBean which is the super class of BookBean, ClothesBean and I want to create a find method like:
    public ProductRemote findAllInCategory(Integer categoryID) throws FinderException, RemoteException;Since each bean is going to have its own table, what's the best way to do this? Is this even possible with CMP find methods?

    I dont think inheritance is going to work here, cos when u write the ejb-ql for the method, there you have to provide the table names and u said each bean has different tables.

  • Use smart mailbox to find email with specific text in attached pdf

    Does anyone known if a smart mailbox can be created to find emails with specific text within a pdf attached document. I know that spotlight can do this and it works fine but it would suite me better to be able to do this in mail.

    After some digging, I found that Spotlight returns the pdf attachment (found within the library/mail/download folder), but not the actual email. The only time it returns the email is if the search text or numerics are coincidentally within the written contents or subject line.
    Yes, i have tried setting up smart mailbox search criteria using the entire message contents but this does not find emails where the text exist within the pdf.
    I've checked spotlight pref.'s and all categories are checked off.
    Essentally, i need the smartbox search criteria to return results where the search text is found within the pdf attachment if possible. If this is not possible, i'll continue using spotlight searches outside of mail.
    I appreciate any help you can offer.

  • Using int and SERIAL as datatypes in cmp Beans.

    Hi
    I�m using a postgresql database with my appserver 7.
    I have some trouble using some of the �normal� db functions.
    Ex SERIAL (or auto_number). Is it possible to create a create method in a cmp bean using SERIAL? I�m using SERIAL as the primary key.
    I also could need to use �LIKE� and �order by�. How can I use these in finder methods?
    Hope someone can help me.
    Best regards
    Kristian Gr�nli

    Hi Kristian,
    AppServer 7 does not support CMP beans with primary key values inserted by the database. However you can use an Unknown Primary Key feature and allow CMP container to provide the values.
    AppServer 7 provides support for all EJB QL features defined in EJB 2.0 spec.
    Regards,
    -marina

  • Junk Characters while persisting data with CMP beans

    Hi
    when i am entering some data and saving the data to the data base using CMP beans ,its converting the data to junk characters like ��@y some times .Do you have any idea why its happening ?pls respond asap

    whats the data type you are using ? whats the App. server, the database ?

Maybe you are looking for

  • Adobe Illustrator CS2 compatible

    Is it compatiable with Windows 7? I have a new computer and cannot find out for sure if it is, and do not wish to install it to only find out it won't work. Thank you, Debbie Warner

  • Cant get airplay icon in iTunes to display

    I have followed all the steps in Troubleshooting AirPlay and AirPlay Mirroring even called tech support, reloaded itunes and turned off windows firewall, what next to try.  It works on another pc with similiar config so I know it works in my network

  • How do I reach a person on the phone at Adobe.  I need help

    can not activate a purchased converter.  How do I call a person at adobe for help?

  • Running my widget plug-in within Xcode

    Hi there I have a widget plug-in I am developing in Xcode. Is there a way to run my plug-in from within Xcode instead of guessing if the plug-in is working when testing my widget in Dashcode? I should mention I don't require a GUI when running the pl

  • Incremental backup - how ?

    Hi, I want to use Rescue & Recovery for backup on a Readynas server using wireless network. The first backup seems to be OK. I understand that the next backup, using the same server address is a incremental backup, but this backup takes for ever to m