EJB QL statements

Hi all,
I'm using EJB, an entity and a session Bean, in a similar way of the common known example "BonusCalculation".
I would like to update a row in my defined database but I have read that it is not posible to use UPDATE statement with EJB QL.
Anyone has ideas about how to update rows in EJB? (using entity and session beans)
very thanks in advance,
ivan.

Hi Vijay;
I'm getting trouble with:
Customer cus = (Customer ) PortableRemoteObject.narrow(home.findByPrimaryKey(new Customer PK(customerID)),Customer.class);
I'm using a similar one:
bonusHome = (BonusLocalHome)ctx.lookup("java:comp/env/ejb/BonusBean");
BonusBean bonusBean = (BonusBean)PortableRemoteObject.narrow(bonusHome.findByPrimaryKey("Ivan"),BonusBean.class);
bonusBean.setBonus("2,57");
I'm getting ClassCastException...Maybe it's not so easy changing between the classes of the bean:
BonusBean.java
BonusLocal.java
BonusLocalHome.java
What do you think about it?
Regards,

Similar Messages

  • Error compiling EJB-QL statement

    I run jboss 3.2.2 with Tomcat.
    When I deploy a CMP EJB I get the
    error below. Do you have any idea of
    what could be the reason of the message?
    Thanks.
    U.
    2003-12-03 15:28:21,437 ERROR [org.jboss.ejb.EntityContainer] Starting failed
    org.jboss.deployment.DeploymentException:
    Error compiling EJB-QL statement '
    select object(o) from myobject o where o.mypro BETWEEN ?1 and ?2
    '; - nested throwable:
    (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "BETWEEN" at line 1, column 62.
    Was expecting one of:
    "=" ...
    "<>" ...

    Well it looks like the word "BETWEEN" is causing the compiler to choke. Instead of "X between 1? and 2?" try "(X > ?1 AND X < ?2) OR (X > ?2 AND X < ?1)"

  • Error deploying Bean with EJB QL statement in ejb-jar.xml

    Hi,
    I'm using Oracle iAS 9i Rev:9.03.
    I've tried to deploy a Entity Bean with the following EJB QL Query:
    &lt;/cmp-field&gt;
    &lt;query&gt;
    &lt;query-method&gt;
    &lt;method-name&gt;findByProcessStep&lt;/method-name&gt;
    &lt;method-params&gt;
    &lt;method-param&gt;java.lang.Integer&lt;/method-param&gt;
    &lt;method-param&gt;java.lang.Integer&lt;/method-param&gt;
    &lt;/method-params&gt;
    &lt;/query-method&gt;
    &lt;ejb-ql&gt;SELECT OBJECT(p) FROM Processparameter AS p WHERE p.stepid=?1 AND p.stepversion=?2&lt;/ejb-ql&gt;
    &lt;/query&gt;
    &lt;/entity&gt;
    Without the query statement everything works fine. As soon as I include it I get the following Error message from dcmctl:
    ADMN-300075
    Nested exception
    Base Exception:
    java.rmi.RemoteException:Failure to initialize EJBQL descriptors: java.lang.RuntimeException: No method found for XML query element: Ambiguous or invalid &lt;query-method&gt;
    Is this an Oracle iAS error or is there an error in my query?
    Thanks in advance
    Jens

    try :
    p.stepid and p.stepversion are correct insert into &lt;cmp-field&gt; ?
    and Processparameter is the correct name of &lt;abstract-schema-name&gt;?
    is your &lt;ejb-ql&gt; insert in the right &lt;entity&gt; ?
    findByProcessStep(Integer, Integer) is the unique name in your ejb-jar? and in the (LocalHome ||RemoteHome)

  • Error in deploying a simple EJB 3.0

    Hi ,
    I am getting the following error while deploying my simple ejb of version 3.0 in Weblogic 9.2.
    Exception preparing module: EJBModule(build) [EJB:011023]An error occurred while reading the deployment descriptor. The error was: Error processing annotations: java.lang.NullPointerException.
    During my evaluation of Weblogic 9.2 for EJB 3.0 , I have got the following questions.
    EJB Specification states that EJB's in EJB 3.0 can be developed and deployed without the need of deployment descriptors. I have created a simple EJB with two file Env.java and EnvBean.java and the source code is given below.
    a) I just complied these class files and when I was trying to deploy without ejb-jar.xml and weblogic-ejb-jar.xml, the console was not at all allowing me to deploy.Why is this so?
    b) After I created a META-INF file under root of classes directory by placing ejb-jar.xml with empty <enterprise-beans> element, console was allowing me to deploy with errors in parsing ejb-jar.xml. The error was either session/entity/mdb is a required under <enterprise-beans> element. Why is this required when there are several examples stating <enterprise-beans> element can be empty.
    c) Later I updated ejb-jar.xml with <session> element under <enterprise-beans> with the following values. I got the above error when deployed with this change.
    I had been struggling to deploy this simple bean for almost a day.Pleas point me if there is any documentation that solves my stated problem or if there is a solution.Thanks in advance.
    regards
    Karim
    ejb-jar.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
    <session>
    <description>This is the stateless ejb</description>
    <display-name>Env Bean</display-name>
    <ejb-name>EnvBean</ejb-name>
    </session>
    </enterprise-beans>
    </ejb-jar>
    Env.java
    package examples ;
    public interface Env {
    public void display();
    EnvBean.java
    package examples;
    import javax.ejb.Remote;
    import javax.ejb.Stateless;
    @Stateless
    @Remote(Env.class)
    public class EnvBean implements Env {
    public void display() {
    System.out.println("Welcome to EJB 3.0");
    }

    Presumably you're using the EJB3 tech preview, and not a vanilla WebLogic 9.2 install, right?
    Can you post the full stack trace?
    -Patrick

  • Problems with string literals in ejb-ql's

    I have a couple EJB-QL's that look like:
    <![CDATA[SELECT OBJECT(o) FROM AssignedStatus AS o WHERE o.recipientID = ?1 AND o.statusID = ?2 AND o.state <> 'r']]>
    which used to work in Orion without a problem but in OC4J I get the following errors:
    com/sun/ejb/ejbql/StringLiteral
    EJB QL statement : 'SELECT OBJECT(o) FROM AssignedStatus AS o WHERE o.recipientID = ?1 AND o.statusID = ?2 AND o.state <> 'r'
    EJB QL method : public abstract com.mongoosetech.reputation.ejb_entity.AssignedStatus com.mongoosetech.reputation.ejb_enti
    ty.AssignedStatusHome.findByRecipientIDAndStatusIDNotRevoked(java.lang.String,java.lang.String) throws javax.ejb.FinderExcept
    ion,java.rmi.RemoteException
    at com.sun.ejb.ejbql.parser.EjbQLParser.parse(EjbQLParser.java:226)
    at com.sun.ejb.ejbql.EjbQLDriver.parse(EjbQLDriver.java:86)
    at com.sun.ejb.sqlgen.SQLGenerator.generateSQLForEjbQLQueries(SQLGenerator.java:628)
    at com.sun.ejb.sqlgen.SQLGenerator.generateSQL(SQLGenerator.java:270)
    at com.evermind.server.ejb.deployment.EJBPackage.init(EJBPackage.java:1947)
    at com.evermind.server.ServerComponent.init(ServerComponent.java:199)
    at com.evermind.server.ejb.EJBPackageDeployment.getPackage(EJBPackageDeployment.java:645)
    at com.evermind.server.ejb.EJBContainer.postInit(EJBContainer.java:513)
    at com.evermind.server.Application.postInit(Application.java:429)
    at com.evermind.server.Application.setConfig(Application.java:136)
    at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:1479)
    at com.evermind.server.ApplicationServer.initializeApplications(ApplicationServer.java:1436)
    at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:1099)
    at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:93)
    at java.lang.Thread.run(Thread.java:479)
    at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:49)
    Error in application ACME Portal: Error loading package at file:/C:/dev/staging/portalstudio/ee/image/deploy/portal/portal-ej
    b.jar, Failure to initialize EJBQL descriptors: com/sun/ejb/ejbql/StringLiteral
    EJB QL statement : 'SELECT OBJECT(o) FROM AssignedStatus AS o WHERE o.recipientID = ?1 AND o.statusID = ?2 AND o.state <> 'r'
    EJB QL method : public abstract com.mongoosetech.reputation.ejb_entity.AssignedStatus com.mongoosetech.reputation.ejb_enti
    ty.AssignedStatusHome.findByRecipientIDAndStatusIDNotRevoked(java.lang.String,java.lang.String) throws javax.ejb.FinderExcept
    ion,java.rmi.RemoteException
    Am I doing something wrong here? These QL's work in several other App Servers so I am lost as to why this doesn't work.

    Kevin,
    We are aware of this bug in the developer's preview and will be fixed when next version of OC4J 9.0.3 will be released.
    regards
    Debu Panda
    Oracle

  • Design problem involving Wildcards and EJB-QL.

    Could someone tell me if this is possible? (my syntax might be a bit off, but bear with me. It's the design I'm interested in, not the exact syntax)
    signature="java.util.Collection findByFullMonty (java.lang.Float price, java.lang.Integer bedrooms... "*snip*
    query="SELECT OBJECT(o) FROM Houses o  WHERE ((o.price =?1) AND (o.bedrooms= ?2) AND ... "*snip*I'd like to be able to use this query with wildcards as default values in a fashion similiar to this:
    Float price = ??  ;//This is where i'm unsure, what is a valid wildcard for a Float?
    Integer bedrooms = ??; // same here for Integer....
    String realtorName = "*"; //i think this is valid wildcard for strings
    *snip*
    //if price supplied set price to input value
    if (myObject.getPrice() != null){
        price = myObject.getPrice();
    //if bedrooms supplied set bedrooms to input value
    if (myObject.getBedrooms()!= null){
        bedrooms = myObject.getBedrooms();
    //always use this finder using wild cards  unless a parameter is supplied
    Collection c = findByFullMonty (price, bedrooms,  realtorName, *snip*); What i'm tyring to achieve is a single query that will work no matter how many of the input paramaters are supplied. Any supplied parameters are used, and those that are not supplied will use wildcard instead. I don't want to make a seperate query for every possible permutaion of supplied input parameters. Can this be done? If so, am I even close or out in left field? Is there a design pattern I should look into for this problem?
    Thanks for any help guys!
    (sorry for the cross-post, i didn't realize this was the approprate place until afterwards)

    Yes, that makes sense, but the EJB-QL statements and finder methods in the home interface have to be defined at deployment time, correct? Once it is deployed, I can't dynamically create the EJB-QL statements and finder methods that are needed. That's the major hurdle I have right now.
    Populating a big 'catch-all' query with wild cards and replacing them with supplied literal values is the only way I could think of to accomplish this dynamically. In my current work around I set a flag for each piece of data supplied. I then decide which (pre-defined) query is needed based on the supplied criteria flags. The problem is, I now have to have 2^n (n = number of possible input parameters) permutaions for the possible queries. For example: say i have: price, bedrooms and bathrooms. I'd need queries for the following cases:
    1 price supplied only
    2 bedrooms supplied only
    3 bathrooms supplied only
    4 price and bedrooms
    5 price and bathrooms
    6 bedrooms and bathrooms
    7 price, bedrooms, bathrooms
    8 nothing supplied (return everything)
    Obviously this is going to break down really fast as the number of input parameters climbs.
    Should I look at using some kind of JDBC code directly to build a query as I go? It seems like I am either approaching this the wrong way or missing something really obvious.

  • Error when deploying an CMP-Entity EJB

    Hi ,
    I am unable to deploy a simple example of CMP ,when i select Entity,then select Deployment Settings->Generate Default SQL,
    My SQL Query is:'SELECT OBJECT(p) FROM Product p' for FfindAllProducts().
    I get the error message:
    ERROR:while generating SQL.
    The SELECT clause has a return type that does not match the return type
    of the select query for which it is defined
    EJB QL statement: 'SELECT OBJECT(p)fROM Product p'
    EJB QL method:public abstract java.util.Collection com.aa.ProductHome.findAllProducts() throws javax.ejb.FinderException,java.rmi.RemoteException.
    Followinng are the codes of My bean
    ProductHome.java
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.Collection;
    public interface ProductHome extends EJBHome
    Product create(String productId,String name , String description , double basePrice) throws CreateException,RemoteException;
    public Product findByPrimaryKey(ProductPK key) throws FinderException,RemoteException;
    public Collection findByName(String name) throws FinderException,RemoteException;
    public Collection findByDescription(String description) throws FinderException,RemoteException;
    public Collection findAllProducts() throws FinderException,RemoteException;
    ProductBean.java
    import javax.ejb.*;
    import java.rmi.RemoteException;
    public class ProductBean implements EntityBean
    protected EntityContext ctx;
    public String productid;
    public String name;
    public String description;
    public ProductBean()
    public String getName() throws RemoteException
    return this.name;
    public void setName(String name) throws RemoteException
    this.name=name;
    public String getDescription() throws RemoteException
    return this.description;
    public void setDescription(String description) throws RemoteException
    this.description=description;
    public String getProductId() throws RemoteException
    return this.productid;
    public void setProductId(String ProductId) throws RemoteException
    this.productid=ProductId;
    public void ejbActivate()
    public void ejbPassivate()
    public void ejbRemove()
    public void ejbLoad()
    public void ejbStore()
    public void setEntityContext(EntityContext ctx)
    this.ctx = ctx;
    public void unsetEntityContext()
    this.ctx = null;
    public void ejbPostCreate(String productId,String name,String description,double baseprice)
    public ProductPK ejbCreate(String productId,String name,String description,double baseprice) throws CreateException,RemoteException
    called ");
    setName(name);
    setProductId(productId);
    setDescription(description);
    return null;
    Product.java
    import javax.ejb.*;
    import java.rmi.RemoteException;
    public interface Product extends EJBObject
    public String getName() throws RemoteException;
    public void setName(String name) throws RemoteException;
    public String getDescription() throws RemoteException;
    public void setDescription(String description) throws RemoteException;
    public String getProductId() throws RemoteException;
    public void setProductId(String productid) throws RemoteException;
    ProductClient.java
    import java.rmi.*;
    import javax.rmi.*;
    import javax.naming.*;
    import javax.ejb.*;
    import java.util.*;
    public class ProductClient
    public static void main(String ars[])
    ProductHome home=null;
    try
    Context initial = new InitialContext();
    Context myEnv = (Context)initial.lookup("java:comp/env");
    Object objref = myEnv.lookup("ejb/TheProduct");
    home = (ProductHome)PortableRemoteObject.narrow(objref,ProductHome.class);
    home.create("123-446-7890","p5-350","350 Mhz Pentium",200 );
    home.create("123-446-7891","p5-400","400 Mhz Pentium",300 );
    home.create("123-446-7892","p5-450","450 Mhz Pentium",400 );
    home.create("123-446-7893","p5-500","500 Mhz Pentium",500 );
    home.create("123-446-7894","p5-550","550 Mhz Pentium",600 );
    Iterator i = home.findByName("p5-400").iterator();
    System.out.println(" Product Match the name of p5-400 " );
    if ( i.hasNext() )
    Product prod = (Product)PortableRemoteObject.narrow(i.next(),Product.class);
    System.out.println(prod.getDescription());
    else
    throw new Exception(" Could not find Product ");
    catch(Exception e)
    System.out.println("Caught Exception " );
    e.printStackTrace();
    finally
    if ( home != null)
    System.out.println(" Destroying all products " );
    try
    Iterator i = home.findAllProducts().iterator();
    while ( i.hasNext() )
    Product prod = (Product)PortableRemoteObject.narrow(i.next(),Product.class);
    if (prod.getProductId().startsWith("123"))
    prod.remove();
    catch (Exception e)
    e.printStackTrace();
    ProductPk.java
    import java.io.Serializable;
    public class ProductPK implements java.io.Serializable
    public String ProductId ;
    public ProductPK(String id)
    this.ProductId = id;
    public ProductPK()
    public String toString()
    return ProductId;
    public int hashCode()
    return ProductId.hashCode();
    public boolean equals(Object Product)
    return ((ProductPK)Product).ProductId.equals(ProductId);

    can u pls tell me u are using ejb1.1 specifications or ejb2.0 specifications.in both cases pls shoe u are descripters so that i can check.

  • What's wrong with this ejb-query?

    Hi people,
    may be i worked too much, may be i've just missed something, but guys, can enyone tell me what the hell is wrong with this GOD DAMNED query?
    <ejb-ql>Select Object(adt) From AddrDataTable AS adt, IN (adt.addresseeQualities) AS aq WHERE adt.season.id = ?1 And aq.aQTemplate.id=?2</ejb-ql>
    That JBoss throws following exception:
    org.jboss.deployment.DeploymentException: Error compiling EJB-QL statement 'Select Object(adt) From AddrDataTable AS adt, IN (adt.addresseeQualities) AS aq WHERE adt.season.id = ?1 And aq.aQTemplate.id=?2'; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "1" at line 1, column 103.
    Was expecting one of:
    "ABS" ...
    "LENGTH" ...
    "LOCATE" ...
    "SQRT" ...
    "+" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <NUMERIC_VALUED_PARAMETER> ...
    <NUMERIC_VALUED_PATH> ...
    at org.jboss.ejb.plugins.cmp.jdbc.JDBCEJBQLQuery.<init>(JDBCEJBQLQuery.java:50)
    The worst thing is that when i remove WHERE clause JBoss keeps silence like a fish - it works fine!
    So, any ideas about this?
    Thank you

    Are you sure the ?1 and ?2 parameters exist in the method for which the query is addressed.
    In the statement adt.season.id I guess season is a CMR field and then season has a CMP field called id
    and the same for aq.aQTemplate.id, aQTemplate being the CMR field and the is being a CMP field in the CMR.
    and in adt.addresseeQualities is a CMR field?
    Looks like a complex query
    SELECT OBJECT(adt) from BEAN AS adt,
    IN(adt.CMR_FIELD) AS aq
    WHERE
    adt.ANOTHER_CMR.ANOTHER_AMR_CMP_FIELD=?1
    AND
    aq.2_CMR_FIELD.2_CMP_FIELD =?2

  • Does OC4J support "LIKE" operation in ejb-ql?

    I have a sql in ejb-jar.xml:
    <query>
              <query-method>
                   <method-name>findByZoneidTypeLnameInfo1</method-name>
                   <method-params>
                        <method-param>java.lang.String</method-param>
                        <method-param>int</method-param>
                        <method-param>java.lang.String</method-param>
                   </method-params>
              </query-method>
              <ejb-ql>
                   <![CDATA[ SELECT OBJECT(a) FROM rrdata AS a WHERE a.zoneid = ?1 AND a.type = ?2 AND a.lname = ?3 AND a.info1 LIKE 'udns%.ultradns.net.' ]]>
              </ejb-ql>
         </query>
    When compiling, I got an error:
    com/sun/ejb/ejbql/StringLiteral
    EJB QL statement : 'SELECT OBJECT(a) FROM rrdata AS a WHERE a.zoneid = ?1 AND a.
    type = ?2 AND a.lname = ?3 AND a.info1 LIKE 'udns%.ultradns.net.''
    EJB QL method : public abstract java.util.Collection com.ultradns.j2ee.compon
    ents.ultradns.rrdata.ejb.RrdataHome.findByZoneidTypeLnameInfo1(java.lang.String,
    int,java.lang.String) throws javax.ejb.FinderException
    at com.sun.ejb.ejbql.parser.EjbQLParser.parse(EjbQLParser.java:226)
    at com.sun.ejb.ejbql.EjbQLDriver.parse(EjbQLDriver.java:86)
    at com.sun.ejb.sqlgen.SQLGenerator.generateSQLForEjbQLQueries(SQLGenerat
    or.java:628)
    at com.sun.ejb.sqlgen.SQLGenerator.generateSQL(SQLGenerator.java:270)
    at com.evermind.server.ejb.deployment.EJBPackage.init(EJBPackage.java:19
    47)
    at com.evermind.server.ServerComponent.init(ServerComponent.java:224)
    at com.evermind.server.ejb.EJBPackageDeployment.getPackage(EJBPackageDep
    loyment.java:645)
    at com.evermind.server.ejb.EJBContainer.postInit(EJBContainer.java:513)
    at com.evermind.server.Application.postInit(Application.java:429)
    at com.evermind.server.Application.setConfig(Application.java:136)
    at com.evermind.server.ApplicationServer.addApplication(ApplicationServe
    r.java:1479)
    at com.evermind.server.ApplicationServer.initializeApplications(Applicat
    ionServer.java:1436)
    at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.jav
    a:1099)
    at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLa
    uncher.java:93)
    at java.lang.Thread.run(Thread.java:484)
    at com.evermind.util.ThreadPoolThread.run(ThreadPoolThread.java:49)
    Error in application dnsmanager: Error loading package at file:/C:/java/oc4j/j2e
    e/home/applications/dnsmanager/ejb/, Failure to initialize EJBQL descriptors: co
    m/sun/ejb/ejbql/StringLiteral
    EJB QL statement : 'SELECT OBJECT(a) FROM rrdata AS a WHERE a.zoneid = ?1 AND a.
    type = ?2 AND a.lname = ?3 AND a.info1 LIKE 'udns%.ultradns.net.''
    EJB QL method : public abstract java.util.Collection com.ultradns.j2ee.compon
    ents.ultradns.rrdata.ejb.RrdataHome.findByZoneidTypeLnameInfo1(java.lang.String,
    int,java.lang.String) throws javax.ejb.FinderException

    I would suggest to try
    "from Brukerkonto as o"
    instead of
    "from Brukerkonto o"

  • A tough one for EJB experts - Stateless session bean spec question

    I am busy learning more about EJBs and came across something confusing regarding the legal operations in the various container callback methods for stateless session beans.
    Specifically, the EJB spec states that in the ejbCreate() method, the SessionContext can be used to obtain a reference to the EJB Object. Now this makes perfect sense with stateful session beans, since the ejbCreate() method isn't called until a client is creating a bean and the container has linked that bean to the client's EJB Object. However, it is my understanding that when it comes to stateless session beans, the container creates the beans and adds them to the bean pool at its leisure. It is not until a business method is called by a client that a stateless bean is actually linked to an EJB object. So, how is it that a stateless bean could ever obtain a reference to an EJB Object from within ejbCreate(). Which EJB Object would it be linked to? This operation just doesn't appear to make sense in that context.
    Can anyone clarify this for me?

    Interesting question. I have such questions all the time! Here's a link to a similar discussion
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=70&t=000905
    Also, I tried this using Weblogic 8.1. Tried to access the EJBObject in ejbCreate before any business method was invoked. I did this by specifying a value for initial-beans-in-free-pool and found that the hash code for the EJBObject was the same for all the bean instances that were created on startup.
    I then invoked a business method and accessed the EJBObject in that method. Again the hash code for the object was the same as the one created on startup.
    Seemed to be that there is a 1:n relation between the EJBObject and bean instances.
    This may be container specific. The spec says the user should be able to invoke the getEJBObject() method in ejbCreate(), its upto the container to comply with it.

  • Problem in Writing select * query in EJB

    Hi all,
    I'm writing    select * from BIT_OEM    in entity bean, but it is not validating the query saying this ==> EJB QL statement is invalid. See General User Output View for details.
    And General User output View is not showing any error description..
    pls help me with this..
    regards,
    Amey

    Hi,
    Try to specify the column names instead of '*'.
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/EJBQL5.html
    Regards
    Ayyapparaj

  • Date range in EJB QL

    I want to query based on a date range. I wrote the following EJB QL:
    "select object(a) from ActionItems as a where a.dueDate
    between ?1 and ?2"
    But when I deployed the application to Oracle's EJB server, I got the following error:
    Auto-deploying biogen.jar (No previous deployment found)... Invalid type for expression (a.dueDate BETWEEN ?1 AND ?2)
    EJB QL statement : 'select object(a) from ActionItems as a where a.dueDate between ?1 and ?2'
    EJB QL method : public abstract java.util.Collection ActionItemsLocalHome.findByDueDateRange(java.sql.Date,java.sql.Date) throws javax.ejb.FinderException
    at com.sun.ejb.ejbql.parser.EjbQLParser.parse EjbQLParser.java:218)
    at com.sun.ejb.ejbql.EjbQLDriver.parse(EjbQLDriver.java:86)
    at com.sun.ejb.sqlgen.SQLGenerator.generateSQLForEjbQLQueries(SQLGenerator.java:704)
    It works fine for a number range, but does not work for a date range.
    Any one has an idea on how to write a correct EJB QL for a query based on date range?
    Thanks.
    Jingzhi

    As far as I know EJB QL can only deal with dates in milliseconds.
    It cannot handle them as java.util.Date or java.SQL.Date

  • EJB lookup failing in DCM managed Oracle AS clustering

    Hi
    My purpose is to test DCM managed Oracle AS clustering:
    For that I have two Oracle Application servers installed in two different machines with
    Version: 10.1.2.0.2 and Installation Type as J2EE and Web Cache
    I created an OracleAS File-based Farm and associated both the instances of AS to the cluster. Then I created One OC4J instance called InstanceOne on the cluster and deployed my Application ear onto the cluster.I also configued web Application and EJB Application State Replication the with OracleAS Cluster (OC4J).
    My Application has one Ejb module and a web module. My stateless Session bean is Spring framework implemented and I am trying to load the Spring Context lookup from the Struts Action Class by using WebApplicationContext.
    My spring context looks like this
    <bean id="jndiTemplate"
    class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.factory.initial">com.evermind.server.rmi.RMIInitialContextFactory</prop>
    <prop key="java.naming.provider.url">opmn:ormi://<server host>:InstanceOne/<Application Name></prop>
    <prop key="java.naming.security.principal">oc4jadmin</prop>
    <prop key="java.naming.security.credentials">admin</prop>
    <prop key="oracle.j2ee.naming.cache.timeout">30</prop>
    <prop key="Dedicated.Connection">yes</prop>
    <prop key="Dedicated.RMIcontext">false</prop>
    <prop key="LoadBalanceOnLookup">true</prop>
    </props>
    </property>
    </bean>
    <bean id="service"
    class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
    <property name="jndiTemplate">
                   <ref bean="jndiTemplate"/>
              </property>
    <property name="jndiName">
    <value>MyServiceEJB</value>
    </property>
    <property name="cacheHome">
    <value>false</value>
    </property>
    <property name="refreshHomeOnConnectFailure">
    <value>true</value>
    </property>
    <property name="businessInterface">
    <value>com.my.springejb.MyBusinessInterface</value>
    </property>
    </bean>
    When I give only one server lookup like
    opmn:ormi://<server host1>:InstanceOne/<Application Name>
    then lookup is working, But by giving two servers in cluster, like opmn:ormi://<server host1>:InstanceOne/<Application Name>, opmn:ormi://<server host2>:InstanceOne/<Application Name>
    I am getting error like this
    06/12/01 19:27:41 java.lang.NumberFormatException: For input string: "InstanceOne"
    06/12/01 19:27:41 at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    06/12/01 19:27:41 at java.lang.Integer.parseInt(Integer.java:468)
    06/12/01 19:27:41 at java.lang.Integer.parseInt(Integer.java:518)
    06/12/01 19:27:41 at com.evermind.server.rmi.RMIInitialContextFactory.getInitialContext(RMIInitialContextFactory.java:237)
    06/12/01 19:27:41 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
    06/12/01 19:27:41 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
    06/12/01 19:27:41 at javax.naming.InitialContext.init(InitialContext.java:219)
    06/12/01 19:27:41 at javax.naming.InitialContext.<init>(InitialContext.java:195)
    06/12/01 19:27:41 at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:105)
    06/12/01 19:27:41 at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:83)
    06/12/01 19:27:41 at org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean.create(SimpleRemoteStatelessSessionProxyFactoryBean.java:19)
    My intension of testing is, if I make one server instance (InstanceOne) down then my lookup should divert all ejb calls to the other server in the cluster, which is not happening at all, and I am getting Server SHUT DOWN exception in the server.
    Can anybody please let me know, whether the approach is correct and is there any problem with Spring lookup which does not support multiple host lookup or anything I am missing in my steps, as I am following the Oracle Application Server High Availability Guide 10g Release 2 (10.1.2)

    you can find an running sample from :
    http://javahowto.blogspot.com/2007/12/calling-weblogic-ejb-3-from-jruby-and.html
    In weblogic, local ejb don't appear in the jndi tree, but , it can be founded ...
    It works into 10.0 and 10.3
    Cheers !

  • Sql query using EJB

    I'm trying to adapt my sql query i use for php in order to return zipcodes using a radial search.
    This is my query that i use in php:
    $strSql2 = "SELECT * FROM Zips where (DEGREES(ACOS(SIN(RADIANS(" . $this->lat . ")) * SIN(RADIANS(lat)) + COS(RADIANS(" . $this->lat . ")) * COS(RADIANS(lat)) * COS(RADIANS(" . $this->lon . " - lon)))) * 69.090909) <= " . $distance;I need to adapt this to work for my finder method in my jaws.xml file, here is what i have so far, i know it doesn't work, especially with the < sign in there ;)
             <finder>
               <name>findByDistance</name>
               <query>(DEGREES(ACOS(SIN(RADIANS(" . $this->lat . ")) * SIN(RADIANS(lat)) + COS(RADIANS(" . $this->lat . ")) * COS(RADIANS(lat)) * COS(RADIANS(" . $this->lon . " -lon)))) * 69.090909) <= " . $distance</query>
               <order>zipcode ASC</order>
             </finder>          Thanks for your help guys.

    Hello,
    If the ">" or "<" are creating the problem then u can use the following approach. Here i am explaing it with an example:
    EJB QL statements are declared in XML deployment descriptors. XML uses the greater than (�>�) and less than (�<�) characters as delimiters for tags, so using these symbols in the EJB QL statements will cause parsing errors unless CDATA sections are used. For example, the following EJB QL statement causes a parsing error, because the XML parser cannot distinguish the use of the �>� symbol from a delimiter to a XML tag:
    <query>
    <query-method>
    <method-name>findWithPaymentGreaterThan</method-name>
    <method-params>java.lang.Double</method-params>
    </query-method>
    <ejb-ql>
    SELECT OBJECT( r ) FROM Reservation r
    WHERE r.amountPaid > ?1
    </ejb-ql>
    </query>
    To avoid this problem, the EJB QL statement should be placed in a CDATA section:
    <query>
    <query-method>
    <method-name>findWithPaymentGreaterThan</method-name>
    <method-params>java.lang.Double</method-params>
    </query-method>
    <ejb-ql>
    <![CDATA[
    SELECT OBJECT( r ) FROM Reservation r
    WHERE r.amountPaid > 300.00
    ]]>
    </ejb-ql>
    </query>
    The CDATA section takes the form <![CDATA[ literal-text ]]>. When an XML processor encounters a CDATA section it doesn�t attempt to parse the contents enclosed by the CDATA section, instead the parser treats it as literal text .

  • Need Help on DATE_SUB on EJB QL

    Hi all,
    Im having problems with my EJB QL statements. Im using MySQL as my database..
    The SQL statement below works perfectly on MySQL:
    select o.dateArrived, o.custName , o.IDCategory
    from tblMessages AS o WHERE o.IDCategory = 0 and DATE_SUB( '"+dateReceived+"' , INTERVAL 2 DAY )  <= o.datArrived ORDER BY o.datArrived DESCWhen transfered the statements to my facade:
    public List getData(String categoryId, String dateReceived){
            return em.createQuery
           ("select o.dateArrived, o.custName , o.IDCategory"+               
           "from TblMessages AS o WHERE o.IDCategory = "+categoryId+" and "+
            "and DATE_SUB( '"+dateReceived+"' ,     INTERVAL 2 DAY )  <= o.dateArrived,             
            ORDER BY o.datReceived DESC").getResultList();
    }It produce an exception: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 2
    Any suggestions?
    Thanks. :)

    can u send me template and xml . i will try at my side. email: [email protected]
    Some times converted templates won't work straight away. you still need to do manual adjustments to make it work based one the requirement u have.
    check this:
    http://bipconsulting.blogspot.com/2009/08/actuate-to-bi-publisher-reports.html

Maybe you are looking for