BMT Entity Bean creation and Weblogic Workshop 8.1

I've looked everywhere I could to find information and an example on how to create a BMP entity bean using Workshop 8.1. Can someone please point me to an example or instructions on how to create this bean? I know how to do it outside of workshop, but there appears to be no option in workshop to specify that my entity bean is BMP and not CMP.
Thanks,
Daryl

Hi Simon,
Are you referring to a 8.1 JWS Web Service ? If yes, unfortunately you cannot deploy this to WLS 9.1. You will need to wait for the 9.2 release and upgrade the web service to use the new JSR-181 annotations and then deploy. The upgrade tool will however take care of all the details associated with the upgrade.
It would be great if you could test the Workshop 9.2 Beta release to confirm if your service upgrade goes through fine.
Cheers
Raj

Similar Messages

  • Entity Beans /JDO and Datawarehousing

    Hi,
    Currently i'm involved in a project, in which we want to generate some very basic custom reports, like turnover calculations etc.
    These reports will be publish on a intranet environment.
    My questions are:
    How do Entity Beans perform when handling large tables (like a few million of rows).
    What about transactions? The datawarehouse will not be updated by the application. Is it therefore advisible to turn it of, in order to gain performance?
    I'm am completely new to JDO, would JDO be a better alternative compared to entity beans when working with large resultsets?
    I hope someone can help
    Thanks and Regards,
    Velli

    hello
    I strongly suggest to use JDBC instead of EJB/JDO. EJB's are great if you need transactions and has a lot of concurrent access. But they are very slow if you read huge data, because for every row an EJB instance is created. For reports you would need to iterate all those instance, in short, performace would be very bad.
    Turning off transactions wont help. Some containers (WEBLogic) allows to configure entity beans as "read only", thus improving performance by data caching in EJB instances. So... if you really need EJB then you can use that.
    However this would not be very effective too, if you really have millions of rows, because it's not possible to keep them all in RAM.
    For several thousands of records it would be very good, but not millions.
    Furthermore, several design patterns suggest to use JDBC in such sitoation. For more information you can read:
    + http://java.sun.com/blueprints/patterns/FastLaneReader.html
    + book "EJB design patterns" (You can find it at TSS)
    + book "Bitter Java"
    Maris Orbidans
    System.out.println(out2.readOutputValue());

  • Caching CMP entity beans in a Weblogic cluster

    We are currently looking for pilot customers for our clustered transactional
              CMP Entity EJB cache. It works with the Weblogic's transaction management
              and CMP implementation to coherently and transactionally cache CMP Entity
              EJBs in a cluster, providing close to zero-latency access to CMP data --
              even for read/write beans.
              Problem Description:
              Performance of J2EE applications using CMP Entity EJBs degrades when running
              in a cluster due to the disabling of Entity EJB caching (i.e. the
              requirement to set db-is-shared=true).
              Requirements:
              1. You are running Weblogic in a cluster
              2. Your application has at least one Weblogic CMP Entity EJB
              3. The data related to your Weblogic CMP Entity EJB is only being updated by
              Weblogic CMP Entity EJBs (i.e. you could set db-is-shared=false if you were
              not clustering)
              Solution Description:
              1. No source code or deployment descriptor changes
              2. One additional automated build step (ANT-compatible)
              3. Configurable cache (e.g. size-limited)
              We plan to begin introduce the product to pilot customers on 28 January
              2002, so if you are interested, please drop me an email at
              [email protected]
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              Clustering Weblogic? You're either using Coherence, or you should be!
              Download a Tangosol Coherence eval today at http://www.tangosol.com/
              

    Could somebody please guide me on this?
    Dipak Jha

  • Log4j and weblogic workshop server 8.1 ?

    Can someone please point out how to setup log4j in weblogic 8.1? I put the log4j.jar file in my server classpath, and in the server startup script I put -Dlog4j.configuration=/path/to/log4.properties in the JAVA_OPTIONS. I can't still get log messages to show in the console. log4j.properties content is:
    log4j.rootCategory=DEBUG, stdout
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c{2} %x - %m%n
    In my code, I use the org.apache.log4j.Category class to log messages. For example, static Category cat = Category.getInstance(MyClass.class);
    cat.debug("a message");
    Is there something I'm doing wrong?
    Thanks.
    gtata

    In my setDomainEnv.cmd script which should be located where your workshop domain is installed, I did the following:
    # Commented out the following line
    @REM set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_CONFIG_FILE% %CLUSTER_PROPERTIES%
    # Set a variable LOG4J_PROPS_FILE to point to the location where my
    # log4j properties file is located. NOTE: Full Path required
    set LOG4J_PROPS_FILE=/bea/user_projects/domains/workshop/log4j.properties
    # Updated my JAVA_PROPERTIES variable to look like the following:
    set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_PROPS_FILE% %CLUSTER_PROPERTIES%
    Originally, I had everything setup correctly except for my JAVA_PROPERTIES. Note that the option
    -Dlog4j.configuration=file:%LOG4J_PROPS_FILE% %CLUSTER_PROPERTIES% has the word "file:" in it.
    What I had that was not working was -Dlog4j.configuration=%LOG4J_PROPS_FILE% %CLUSTER_PROPERTIES%
    so I added the file: infront of the LOG4J_PROPS_FILE variable.
    Hope this helps.
    Gabsaga

  • Soap binding in wsdl and weblogic workshop

    Dear newsgroup,
    I'm trying to develop a webservice with workshop 8.1. In my case, I already have
    a "WSDL" file for the service I want to develop.
    So I created a "Schema Project", imported the wsdl file in it (workshop automatically
    compiled it !!) and generated a webservice from it. I then created a webservice
    project and moved the generated "jws" file in the webservice project.
    So far with no problem.
    Now I opened the "jws" file and saw there is this error:
    "ERROR: The binding for <Op name> does not declare one part"
    "SUGGESTION: A document literal binding must have at most one part. Make sure
    you have a WSDL that declares just one part for each message with a document literal
    binding."
    Indeed my wsdl has messages with more than one part. It looks like this:
    <wsdl:message name="SubmitSMSIn">
    <wsdl:part name="GNSHeaderHeader" element="fwk:GNSHeader">
    </wsdl:part>
    <wsdl:part name="GNSCredentialsHeader" element="fwk:GNSCredentials">
    </wsdl:part>
    <wsdl:part name="SubmitSMSRequestBody" element="sms:SubmitSMSRequest">
    </wsdl:part>
    </wsdl:message>
    And corresponding binding looks like this:
    <wsdl:binding name="smsBinding" type="smsPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"
    />
    <wsdl:operation name="SubmitSMS">
    <soap:operation style="document" soapAction="http://vodafone.net/ns/gns/sms/SubmitSMS">
    </soap:operation>
    <wsdl:input name="SubmitSMSInput">
    <soap:body use="literal" parts="SubmitSMSRequestBody">
    </soap:body>
    <soap:header use="literal" message="SubmitSMSIn" part="GNSHeaderHeader"
    wsdl:required="true">
    </soap:header>
    <soap:header use="literal" message="SubmitSMSIn" part="GNSCredentialsHeader"
    wsdl:required="true">
    </soap:header>
    </wsdl:input>
    <wsdl:output name="SubmitSMSOutput">
    <soap:body use="literal" parts="SubmitSMSResponseBody">
    </soap:body>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    MY QUESTION: Is this a workshop webservice limitation? I thought after reading
    wsdl specification,(URL: http://www.w3.org/TR/wsdl.html#_soap-b, example 3), that
    this should be possible.
    What am I doing wrong.
    Thanks for any help.
    -- Asit Bhattacharya

    Hi Asit,
    Personally, I find dealing with the WSDL/SOAP language a humbling
    experience and welcome the day that their syntax is completely buried
    with the use of tools; to that end, I would recommend that you use the
    WS-I test tools to validate/confirm all of the Rxxx issues.
    Regards,
    Bruce
    Asit Bhattacharya wrote:
    >
    Hi Bruce,
    Yes, you are right. "R2210" indeed does say that. Interestingly, it starts like
    this:
    "If a document-literal binding in a DESCRIPTION does not specify the parts attribute
    on a soapbind:body element, the corresponding abstract wsdl:message MUST define
    zero or one wsdl:parts."
    Please NOTE the "if" part of the recommendation. As I understand, it is saying
    when "parts" attribute is not specified in "soapbind:body" element then corresponding
    "wsdl:message" is required to define zero or one "wsdl:parts".
    In my original wsdl file example, I do have "parts" attribute specified for the
    "soapbind:body" element. To me that that should be valid. What do you say.
    Sincerely,
    Asit Bhattacharya.
    Bruce Stephens <[email protected]> wrote:
    Hi Asit,
    R2210 says: ...wsdl:message MUST define zero or one wsdl:parts.
    I might suggest that you try your WSDL with the WS-I test tools. They
    have a mode to consume and analyze WSDL that will give you a detailed
    response correlated with the basic profile.
    Regards,
    Bruce
    Asit Bhattacharya wrote:
    Hi Bruce,
    Thanks for your reply,
    WS-I Basic Profile "R2201" says the following:
    "A document-literal binding in a DESCRIPTION MUST, in each of its soapbind:body
    element(s), have at most one part listed in the parts attribute, ifthe parts
    attribute is specified."
    It does not restrict a meesage (that is used in doc/lit soap binding)to have
    multiple parts. If you look in my example wsdl (specially the soap:bindingportion),
    you'll see I'm only using one part for soap:body binding.
    Could you please explain why do you think that the SUGGESTION is valid?
    Thanks for your help.
    Regards.
    Asit Bhattacharya.
    Bruce Stephens <[email protected]> wrote:
    Hello,
    The suggestion is valid. You might want to reference the extensive
    work
    on this issue by the WS-I folks [1], see R2201 and following.
    Regards,
    Bruce
    [1]
    http://www.ws-i.org/Profiles/Basic/2003-08/BasicProfile-1.0a.html
    Asit Bhattacharya wrote:
    Dear newsgroup,
    I'm trying to develop a webservice with workshop 8.1. In my case,
    I
    already have
    a "WSDL" file for the service I want to develop.
    So I created a "Schema Project", imported the wsdl file in it (workshopautomatically
    compiled it !!) and generated a webservice from it. I then createda webservice
    project and moved the generated "jws" file in the webservice project.
    So far with no problem.
    Now I opened the "jws" file and saw there is this error:
    "ERROR: The binding for <Op name> does not declare one part"
    "SUGGESTION: A document literal binding must have at most one part.Make sure
    you have a WSDL that declares just one part for each message with
    a
    document literal
    binding."
    Indeed my wsdl has messages with more than one part. It looks likethis:
    <wsdl:message name="SubmitSMSIn">
    <wsdl:part name="GNSHeaderHeader" element="fwk:GNSHeader">
    </wsdl:part>
    <wsdl:part name="GNSCredentialsHeader" element="fwk:GNSCredentials">
    </wsdl:part>
    <wsdl:part name="SubmitSMSRequestBody" element="sms:SubmitSMSRequest">
    </wsdl:part>
    </wsdl:message>
    And corresponding binding looks like this:
    <wsdl:binding name="smsBinding" type="smsPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"
    />
    <wsdl:operation name="SubmitSMS">
    <soap:operation style="document" soapAction="http://vodafone.net/ns/gns/sms/SubmitSMS">
    </soap:operation>
    <wsdl:input name="SubmitSMSInput">
    <soap:body use="literal" parts="SubmitSMSRequestBody">
    </soap:body>
    <soap:header use="literal" message="SubmitSMSIn"part="GNSHeaderHeader"
    wsdl:required="true">
    </soap:header>
    <soap:header use="literal" message="SubmitSMSIn"part="GNSCredentialsHeader"
    wsdl:required="true">
    </soap:header>
    </wsdl:input>
    <wsdl:output name="SubmitSMSOutput">
    <soap:body use="literal" parts="SubmitSMSResponseBody">
    </soap:body>
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
    MY QUESTION: Is this a workshop webservice limitation? I thought
    after
    reading
    wsdl specification,(URL: http://www.w3.org/TR/wsdl.html#_soap-b,
    example
    3), that
    this should be possible.
    What am I doing wrong.
    Thanks for any help.
    -- Asit Bhattacharya

  • Can I deploy the entity bean in different jar files?

    I have an application EAR, which contains several JARs. I have an entity bean A that has relationships with 2 other different entity beans B and C in the same DB. Now, I have to deploy this entity A together with B in AB.jar, and A with C in AC.jar. Both AB.jar and AC.jar are modules of the same application EAR file. They all use the same data sources to the same database, and named by different <ejb-name>.
    I have no problem with deploying the app to WebLogic 8.1. But the JSP page accessing entity A got errors. Sometime, it got error complaining that the container-generated ejbFindAccount mehtod is abstract.
    My questions are,
    Can an entity bean be defined twice in 2 different jars?
    When container load AB.jar and AC.jar, does it generate the finder methods twice?
    I guess there are some name conflicts going on here. What should I do to avoid it?
    Any comments are very much appreciated.

    Thanks for your answer, but how can I use it in connection with relationships?
    <!-- ********************************************************************** -->
    <!-- Relationship: View to FrameworkUser                                             -->
    <!-- ********************************************************************** -->
    <ejb-relation id="View-FrameworkUser">
         <description></description>
         <ejb-relation-name>View-FrameworkUser</ejb-relation-name>
         <ejb-relationship-role>
              <ejb-relationship-role-name>Views-have-FrameworkUser</ejb-relationship-role-name>
              <multiplicity>Many</multiplicity>
              <relationship-role-source>
                   <ejb-name>View</ejb-name>
              </relationship-role-source>
              <cmr-field>
                   <cmr-field-name>frameworkUser</cmr-field-name><!-#- getter/setter -#->
                   <cmr-field-type>java.util.Collection</cmr-field-type>
              </cmr-field>
         </ejb-relationship-role>
         <!-#- *************** -#->
         <ejb-relationship-role>
              <ejb-relationship-role-name>FrameworkUser-has-Views</ejb-relationship-role-name>
              <multiplicity>One</multiplicity>
              <relationship-role-source>
                   <!-#- *******REFERENCE******** -#->
                   <ejb-name>ejb_foo_jar2_ejb.jar#FrameworkUser</ejb-name>
                   <!-#- *******REFERENCE******** -#->
              </relationship-role-source>
         </ejb-relationship-role>
    </ejb-relation>
    ...this obviously doesn't work...
    Do I have to write a new <entity> where I define the referenced entity?

  • Does WLS 6.1 sp2 allow (bean managed) entity beans to have transaction mode NOTSUPPORTED?

    Hi,
    I have created two bean managed entity beans, User and Role, abstracting users
    and groups in a ldap base. A User may have more than one Role. This is represented
    by a (bean managed) 1:many relationship directed from User to Role. For some weird
    reasons I get a transaction rollback when reading data, when transactions are
    turned on (REQUIRED).
    While we where running WLS 6.1 sp1 we had no problems with this as we could set
    transaction to NOTSUPPORTED for these two EJBs. Due to other hickups we had to
    upgrade to sp2 and suddenly the error reappears leading me to believe that NOTSUPPORTED
    isn't allowed anymore by the WLS. I know that NOTSUPPORTED isn't required by the
    EJB spec, but containers may support it and obviously WLS used to do just that.
    I have not seen any change in the release notes of sp2 that indicates that this
    behaviour has changed.
    Does anybody know if WLS really doesn't support NOTSUPPORTED for enity beans anymore
    in sp2?
    If anybody are curiuos or have any good ideas, the stacktrace I get is:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    Start server side stack trace:
    java.rmi.RemoteException: EJB Exception: ; nested exception is:
         javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    java.util.ConcurrentModificationException
         at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:535)
         at java.util.LinkedList$ListItr.next(LinkedList.java:476)
         at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:370)
         at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:481)
         at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:551)
         at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:88)
         at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:980)
         at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1504)
         at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:216)
         at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:190)
         at weblogic.ejb20.internal.BaseEJBLocalObject.postInvoke(BaseEJBLocalObject.java:207)
         at com.takecargo.domainentities.role.RoleBean_1ipw6_ELOImpl.getName(RoleBean_1ipw6_ELOImpl.java:86)
         at com.takecargo.domainentities.role.RoleConverter.getVOforRoleLocal(RoleConverter.java:51)
    Any kind of help would be appreciated:)
    Regards,
    Brynjar Glesnes

    WLS support NotSupported on Entity Beans.
    It looks like you've hit a bug in the EJB container where an internal Collection class has been modified while the
    container is running through an iterator on it.
    You should open a case with [email protected]
    -- Rob
    Brynjar Glesnes wrote:
    Hi,
    I have created two bean managed entity beans, User and Role, abstracting users
    and groups in a ldap base. A User may have more than one Role. This is represented
    by a (bean managed) 1:many relationship directed from User to Role. For some weird
    reasons I get a transaction rollback when reading data, when transactions are
    turned on (REQUIRED).
    While we where running WLS 6.1 sp1 we had no problems with this as we could set
    transaction to NOTSUPPORTED for these two EJBs. Due to other hickups we had to
    upgrade to sp2 and suddenly the error reappears leading me to believe that NOTSUPPORTED
    isn't allowed anymore by the WLS. I know that NOTSUPPORTED isn't required by the
    EJB spec, but containers may support it and obviously WLS used to do just that.
    I have not seen any change in the release notes of sp2 that indicates that this
    behaviour has changed.
    Does anybody know if WLS really doesn't support NOTSUPPORTED for enity beans anymore
    in sp2?
    If anybody are curiuos or have any good ideas, the stacktrace I get is:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    Start server side stack trace:
    java.rmi.RemoteException: EJB Exception: ; nested exception is:
    javax.ejb.TransactionRolledbackLocalException: EJB Exception:
    - with nested exception:
    [javax.ejb.EJBException
    - with nested exception:
    [weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
    sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
    [java.util.ConcurrentModificationException]]]
    java.util.ConcurrentModificationException
    at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:535)
    at java.util.LinkedList$ListItr.next(LinkedList.java:476)
    at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:370)
    at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:481)
    at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:551)
    at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:88)
    at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:980)
    at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1504)
    at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:216)
    at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:190)
    at weblogic.ejb20.internal.BaseEJBLocalObject.postInvoke(BaseEJBLocalObject.java:207)
    at com.takecargo.domainentities.role.RoleBean_1ipw6_ELOImpl.getName(RoleBean_1ipw6_ELOImpl.java:86)
    at com.takecargo.domainentities.role.RoleConverter.getVOforRoleLocal(RoleConverter.java:51)
    Any kind of help would be appreciated:)
    Regards,
    Brynjar Glesnes

  • CMP Entity Beans / DB activity

    Hello everyone
    I'm using BEA Weblogic ejbgen for generating entity bean implementations and interfaces.
    When I use the finder methods defined in the home-interface, naturally an sql-query is performed to the predefined database.
    When I use the set-methods in the remote interface, is an sql-update performed on each method-invocation? in other words, if the entity has a lot of fields, and each field is populated with a seperate set-method, there will be a lot of databse activity while performing this update on the entity?
    I'm trying to analyze a system, and there is a lot of activity goin on. A lot of remote calls and even more entity-operations.
    First, 60 000 remote method calls are performed in a row. These return certain id's that are used for finding entity objects and performing operations on them. Lucky me...
    Thx.
    Juha, SCJP
    ----

    Hello ,
    Instead of exposing a get/set method for each arribute of your bean (corresponding to database table) expose only one object.
    For example
    public class CustomerBean implements javax.ejb.EntityBean{
    private CustomerVO objCustomer;
    private String customerName;
    private String customerMail;
    private String customerType;
    public CustomerVO getCustomer(){
    return this.objCustomer;
    public void setCustomer(CustomerVO objCustomer){
    this.objCustomer = objCustomer;
    public void ejbStore(){
    customerName = objCustomer.getName();
    customerMail = objCustomer.getMail();
    customerType = objCustomer.getType();
    HTH
    VJ

  • Failure to create entity bean with CMP2 under JBOSS + Postgresql

    I have written a simple jsp programme using JBOSS 4 DR2 with postgresql 7.3.3 whereby a simple entity bean could be created into a table in the postgresql 7.3.3 table. However I kept getting the exception message [ javax.ejb.CreateException :Erro checking if entity exists:java.sql.SQLException: ERROR:parser:parse error at or near "=" at character 39 ]
    I have even examined the logfile created under the cygwin postgresql , the log output record produce the error FATAL : unsupported frontend protocol ,with next line read [ERROR:parser:parse error at or near "=" at character 39 .
    I have no idea why this is happening? The postgrsql 7.3.3 was run under cygwin using the command: pg_ctl start _D {data directory} -l logfile -o "-p 5432"
    My guess is that this may not be the Jboss-postgresql data source configuration error since I am able the verify the existence postgresql jndi ,datasource and connector service under the jboss console.Somehow it just got something to do with the jsp programme in the way it was written may be ? But it should not pose a great problem, since i am trying to create a simple entity bean only.
    By the way the entity bean creation statement is home.create("123"),to further verify that the home & remote interface was working ,I have the object context printed out before the creation, and it appeared OK.
    Thanks in advance for those willing to help me to resolve the issues

    I have managed to get the debug from the postmaster , it all boils down to the query [SELECT COUNT(*) FROM {TABLE} WHERE ={CMP FILED}="123"] , the = sign after the 'WHERE' responsible for the failure , but I am still puzzle why it would happen as such?
    Any helper ?
    Thanks

  • Pooling of Entity beans

    Hi,
    How is pooling of entity beans supported in Weblogic? If a value is provided for
    max_beans_in_free_pool, then the Weblogic server creates a particular number of
    entity bean instances in the pool? What's the role of max-beans-in-cache?
    Regards,
    Indhu

    Thanks Seth for your info
    Indhu
    Seth White <[email protected]> wrote:
    >
    The docs are incorrect. You may configure a pool for your entity beans.
    Seth
    indhu wrote:
    Hi Ryan,
    Thanks for your reply.
    In the entity-descriptor element of weblogic-ejb-jar.xml, pool elementis there,
    which consists of max-beans-in-free-pool and initial-beans-in-free-pool.The document
    says that the pool element configures the behavior of the WebLogicServer free
    pool for stateless session and message driven EJBs.It means that wecan't use
    those elements to set free pool for entity beans?
    Regards,
    Indhu
    "Ryan LeCompte" <[email protected]> wrote:
    Hello Indhu,
    Refer to the following links for answers to your questions:
    http://edocs.bea.com/wls/docs70/ejb/EJB_environment.html#1135029
    http://edocs.bea.com/wls/docs70/ejb/reference.html#1071069
    http://edocs.bea.com/wls/docs70/ejb/reference.html#1071125
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "indhu" <[email protected]> wrote:
    Hi,
    How is pooling of entity beans supported in Weblogic? If a value
    is
    provided
    for
    max_beans_in_free_pool, then the Weblogic server creates a particular
    number of
    entity bean instances in the pool? What's the role of max-beans-in-cache?
    Regards,
    Indhu

  • Problem with 1-to-many relationship between entity beans

    Hi All!
    I have two tables TMP_GROUP and TMP_EMPLOYEE with following fields:
    TMP_GROUP: ID, CAPTION, COMMENT, STATUS.
    TMP_EMPLOYEE: ID, LOGIN, GROUP_ID.
    For this tables i create two entity beans GROUP and EMPLOYEE respectively.
    The relationship looks like this
    descriptor ejb.xml:
    <ejb-relation>
                <description>description</description>
                <ejb-relation-name>employeesOfGroup</ejb-relation-name>
                <ejb-relationship-role>
                    <ejb-relationship-role-name>com.mypackage.GroupBean</ejb-relationship-role-name>
                    <multiplicity>One</multiplicity>
                    <relationship-role-source>
                        <ejb-name>GroupBean</ejb-name>
                    </relationship-role-source>
                    <cmr-field>
                        <cmr-field-name>employees</cmr-field-name>
                        <cmr-field-type>java.util.Collection</cmr-field-type>
                    </cmr-field>
                </ejb-relationship-role>
                <ejb-relationship-role>
                    <ejb-relationship-role-name>com.mypackage.EmployeeBean</ejb-relationship-role-name>
                    <multiplicity>Many</multiplicity>
                    <relationship-role-source>
                        <ejb-name>EmployeeBean</ejb-name>
                    </relationship-role-source>
                </ejb-relationship-role>
            </ejb-relation>
    descriptor persistent.xml:
    <table-relation>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>GroupBean</ejb-name>
                        <cmr-field>employees</cmr-field>
                   </table-relationship-role>
                   <table-relationship-role
                        key-type="NoKey">
                        <ejb-name>EmployeeBean</ejb-name>
                        <fk-column>
                             <column-name>GROUP_ID</column-name>
                             <pk-field-name>ejb_pk</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
              </table-relation>
    Now i implement business method:
    public Long addEmployee(String login, long groupId) {
              Long result;
              try {
                   EmployeeLocal employee = employeeHome.create(login);
                   GroupLocal group =
                        groupHome.findByPrimaryKey(new Long(groupId));
                   Collection employees = group.getEmployees();
                   employees.add(employee);
                   result = (Long) employee.getPrimaryKey();
              } catch (CreateException ex) {
                   result = new Long(0);
              } catch (FinderException ex) {
                   result = new Long(0);
              return result;
    When i call this method from web service, the following exception is raised:
    com.sap.engine.services.ejb.exceptions.BaseTransactionRolledbackLocalException: Exception in method com.mypackage.GroupLocalHomeImpl0.findByPrimaryKey(java.lang.Object).
    P.S.
    1) I have transaction attribute set to "Required" for all methods of all beans
    2) I have unique index for each table:
    TMP_GROUP_I1: CAPTION
    TMP_EMPLOYEE_I1: LOGIN (however i think GROUP_ID must be added here too)
    3) I tried many:many relationship with this tables and it works fine
    4) I try another implementation of addEmployee method with
    EmployeeLocal employee = employeeHome.create(login, groupId);
    without using GroupLocal cmr-field and GroupLocalHome findByPrimaryKey method, the result is same error.
    Can somebody help me with this problem?
    Thanks in advance.
    Best regards, Abramov Andrey.

    gimbal2 wrote:
    1: The @JoinColumn on the listOfDepartments collection in Company is wrong. It should be something like this for a bidirectional relationship:
    @OneToMany(mappedBy="company") // company is the matching property name in Department
    private List <Department> listOfDepartment = new ArrayList<Department>();Note that I removed the fetch configuration; onetomany is fetched lazy by design. Saves some clutter eh.
    2: use a Set in stead of a List (hibernate doesn't like lists much in entities and will break when you create slightly more complex entity relations)
    3: don't just slap cascades on collections, especially of type ALL. Do it with care. In the many years I've been using JPA I've only had to cascade deletes in very specific situations, maybe once or twice. I never needed any of the other cascade types, they just invite sloppy code if you ask me. When working with persistence you should apply a little precision.I made all changes as you mentioned but still compID in department table shows null value...

  • Problem with 1:many relationship between entity beans.

    Hi All!
    I have two tables TMP_GROUP and TMP_EMPLOYEE with following fields:
    TMP_GROUP: ID, CAPTION, COMMENT, STATUS.
    TMP_EMPLOYEE: ID, LOGIN, GROUP_ID.
    For this tables i create two entity beans GROUP and EMPLOYEE respectively.
    The relationship looks like this
    descriptor ejb.xml:
    <ejb-relation>
                <description>description</description>
                <ejb-relation-name>employeesOfGroup</ejb-relation-name>
                <ejb-relationship-role>
                    <ejb-relationship-role-name>com.mypackage.GroupBean</ejb-relationship-role-name>
                    <multiplicity>One</multiplicity>
                    <relationship-role-source>
                        <ejb-name>GroupBean</ejb-name>
                    </relationship-role-source>
                    <cmr-field>
                        <cmr-field-name>employees</cmr-field-name>
                        <cmr-field-type>java.util.Collection</cmr-field-type>
                    </cmr-field>
                </ejb-relationship-role>
                <ejb-relationship-role>
                    <ejb-relationship-role-name>com.mypackage.EmployeeBean</ejb-relationship-role-name>
                    <multiplicity>Many</multiplicity>
                    <relationship-role-source>
                        <ejb-name>EmployeeBean</ejb-name>
                    </relationship-role-source>
                </ejb-relationship-role>
            </ejb-relation>
    descriptor persistent.xml:
    <table-relation>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>GroupBean</ejb-name>
                        <cmr-field>employees</cmr-field>
                   </table-relationship-role>
                   <table-relationship-role
                        key-type="NoKey">
                        <ejb-name>EmployeeBean</ejb-name>
                        <fk-column>
                             <column-name>GROUP_ID</column-name>
                             <pk-field-name>ejb_pk</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
              </table-relation>
    Now i implement business method:
    public Long addEmployee(String login, long groupId) {
              Long result;
              try {
                   EmployeeLocal employee = employeeHome.create(login);
                   GroupLocal group =
                        groupHome.findByPrimaryKey(new Long(groupId));
                   Collection employees = group.getEmployees();
                   employees.add(employee);
                   result = (Long) employee.getPrimaryKey();
              } catch (CreateException ex) {
                   result = new Long(0);
              } catch (FinderException ex) {
                   result = new Long(0);
              return result;
    When i call this method from web service, the following exception is raised:
    com.sap.engine.services.ejb.exceptions.BaseTransactionRolledbackLocalException: Exception in method com.mypackage.GroupLocalHomeImpl0.findByPrimaryKey(java.lang.Object).
    P.S.
    1) I have transaction attribute set to "Required" for all methods of all beans
    2) I have unique index for each table:
    TMP_GROUP_I1: CAPTION
    TMP_EMPLOYEE_I1: LOGIN (however i think GROUP_ID must be added here too)
    3) I tried many:many relationship with this tables and it works fine
    4) I try another implementation of addEmployee method with
    EmployeeLocal employee = employeeHome.create(login, groupId);
    without using GroupLocal cmr-field and GroupLocalHome findByPrimaryKey method, the result is same error.
    Can somebody help me with this problem?
    Thanks in advance.
    Best regards, Abramov Andrey.

    I have posted excerpts from my orion-ejb-jar.xml file in this posting: Problem mapping a 1:M relationship between two entity EJBs w/ a compound PK
    Sorry for the duplicate postings, but I was getting errors on the submission.
    April

  • Error in locating entity bean

    Hi
    when i tested my first session bean by IBM websphere Universal Test Client , i got the following error when execute getBookForPlatform(String workPlatform) saying error in locating entity bean Book_catalog and i tried to test Book_catalog entity bean and it's working successfuly but i do not know why seesion bean could not locate it ? :
    ========== the Error ===========
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.RemoteException: ; nested exception is:
    javax.ejb.EJBException: Error getting TechLibBook_catalogLocalHome from findByPlatform method:Error locating TechLibBook_catalogLocalHome: Context: localhost/nodes/localhost/servers/server1, name: ejb/Book_catalog: First component in name Book_catalog not found.
    at com.ibm.CORBA.iiop.UtilDelegateImpl.mapSystemException(UtilDelegateImpl.java:156)
    at com.ibm.CORBA.iiop.UtilDelegateImpl.wrapException(UtilDelegateImpl.java:684)
    at javax.rmi.CORBA.Util.wrapException(Util.java:295)
    at apress.wsad.techlib._TechLibFacade_Stub.getBookForPlatform(_TechLibFacade_Stub.java:267)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    at com.ibm.etools.utc.model.ReflectionMethodModel.invoke(ReflectionMethodModel.java:68)
    at com.ibm.etools.utc.servlet.InvokeServlet.invoke(InvokeServlet.java:110)
    at com.ibm.etools.utc.servlet.InvokeServlet.doPost(InvokeServlet.java:366)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:974)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:555)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
    at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
    at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
    at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:114)
    at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
    at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
    at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
    Caused by: java.rmi.RemoteException: ; nested exception is:
    javax.ejb.EJBException: Error getting TechLibBook_catalogLocalHome from findByPlatform method:Error locating TechLibBook_catalogLocalHome: Context: localhost/nodes/localhost/servers/server1, name: ejb/Book_catalog: First component in name Book_catalog not found.
    at com.ibm.ejs.container.RemoteExceptionMappingStrategy.mapEJBException(RemoteExceptionMappingStrategy.java:379)
    at com.ibm.ejs.container.RemoteExceptionMappingStrategy.mapException(RemoteExceptionMappingStrategy.java:112)
    at com.ibm.ejs.container.RemoteExceptionMappingStrategy.setUncheckedException(RemoteExceptionMappingStrategy.java:202)
    at com.ibm.ejs.container.EJSDeployedSupport.setUncheckedException(EJSDeployedSupport.java:296)
    at apress.wsad.techlib.EJSRemoteStatelessTechLibFacade_3526fe64.getBookForPlatform(EJSRemoteStatelessTechLibFacade_3526fe64.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
    at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
    at com.ibm.rmi.util.ProxyUtil$4.run(ProxyUtil.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.ibm.rmi.util.ProxyUtil.invokeWithClassLoaders(ProxyUtil.java:701)
    at com.ibm.CORBA.iiop.ClientDelegate.invoke(ClientDelegate.java:1084)
    at $Proxy1.getBookForPlatform(Unknown Source)
    at apress.wsad.techlib._TechLibFacade_Stub.getBookForPlatform(_TechLibFacade_Stub.java:260)
    ... 29 more
    Caused by: javax.ejb.EJBException: Error getting TechLibBook_catalogLocalHome from findByPlatform method:Error locating TechLibBook_catalogLocalHome: Context: localhost/nodes/localhost/servers/server1, name: ejb/Book_catalog: First component in name Book_catalog not found.
    at apress.wsad.techlib.TechLibFacadeBean.getBookForPlatform(TechLibFacadeBean.java:92)
    at apress.wsad.techlib.EJSRemoteStatelessTechLibFacade_3526fe64.getBookForPlatform(EJSRemoteStatelessTechLibFacade_3526fe64.java:22)
    ... 39 more
    ===== End of Error ======
    ====== the source code of session bean=======
    package apress.wsad.techlib;
    import javax.ejb.*;
    import javax.naming.*;
    import javax.rmi.*;
    import java.rmi.*;
    import java.lang.*;
    import java.util.*;
    public class TechLibFacadeBean implements javax.ejb.SessionBean
    private javax.ejb.SessionContext mySessionCtx;
    // Variable to keep the Home Local refernce to TechLibBook_catalog object
    private TechLibBook_catalogLocalHome catalogLocalHome = null ;
    // Method to get the Home Interface of the Book_catalog entity bean.
    private TechLibBook_catalogLocalHome getCatalogLocalHome()
    throws RemoteException
    try
    if (catalogLocalHome == null)
    InitialContext initContext = new InitialContext();
    Object objRef =initContext.lookup("ejb/Book_catalog");
    catalogLocalHome = (TechLibBook_catalogLocalHome) objRef;
    return (TechLibBook_catalogLocalHome) objRef;
    else
    return catalogLocalHome;
    catch (NamingException ne)
    System.out.println("Error locating TechLibBook_catalogLocalHome: " +
    ne.getMessage());
    throw
    new RemoteException("Error locating TechLibBook_catalogLocalHome: " +
    ne.getMessage());
    // This business method must be promoted to the remote interface
    public Vector getBookForPlatform(String workPlatform)
    throws FinderException
    Vector bookVector = new Vector();
    TransportBean transObject;
    TechLibBook_catalogLocal bookCatalogLocal = null;
    Collection collBookRecords;
    try
    collBookRecords =
    getCatalogLocalHome().findByPlatform(workPlatform);
    Iterator iterator = collBookRecords.iterator();
    while (iterator.hasNext())
    bookCatalogLocal =
    (TechLibBook_catalogLocal) iterator.next();
    transObject = new TransportBean();
    transObject.catalogNumber = bookCatalogLocal.getCatalog_number();
    transObject.author = bookCatalogLocal.getAuthor();
    transObject.bookTitle = bookCatalogLocal.getBook_title();
    transObject.location = bookCatalogLocal.getLocation();
    transObject.platform = bookCatalogLocal.getPlatform();
    transObject.txnDate = bookCatalogLocal.getLanguage();
    bookVector.addElement(transObject);
    } // End of while
    } // End of try
    catch(FinderException fe)
    System.out.println("Error executing findByPlatform method: " +
    fe.getMessage());
    throw
    new EJBException("Error executing findByPlatform method: " +
    fe.getMessage());
    catch(Exception e)
    System.out.println("Error getting TechLibBook_catalogLocalHome from findByPlatform method:" + e.getMessage());
    throw
    new EJBException("Error getting TechLibBook_catalogLocalHome from findByPlatform method:" + e.getMessage());
    return bookVector;
    public javax.ejb.SessionContext getSessionContext()
    return mySessionCtx;
    public void setSessionContext(javax.ejb.SessionContext ctx)
    mySessionCtx = ctx;
    * ejbCreate
    public void ejbCreate() throws javax.ejb.CreateException
    public void ejbActivate()
    public void ejbPassivate()
    public void ejbRemove()
    ==== End if source code =========
    Please tell me what's the problem ?
    with regards

    i found what's the problem i made the url for lookup as the following:
    lookup("java:comp/env/Book_catalog")
    instead of
    lookup("ejb/Book_catalog")
    could anyone tell me what's the difference between 'java:comp/env/' and without it
    by the way i used for lookup Datasource the following and it's working
    DataSource dataSource = (DataSource)jndiContext.lookup("jdbc/TECHBOOK");
    thanks

  • Deploying BMP Entity Bean with primary key calss

    Hi,
    I am using EJB 2.0 with and websphere studio 5.0 and database is sql server 2000.
    My BMP Entity bean has a primary key class.From my client I am invoking the Entity Bean by calling it's findbyprimarykey method.
    The home interface of my findbyprimarykey method returns a class of type Remote.But in the Entity Bean class,the return type is the primarykey class type.
    My problem is invoking this findbyprimarykey from the client to get the remote interface so that the other business methods of the entity bean can be called.
    The control goes into the ejbFindbyPrimaryKey but when it is returing from the Entity Bean class,it gives a remote exception (as the return type in Entity Bean class and Home interface are different for the findbyprimarykey method).
    I think that somewhere in the deployment decriptor in my websphere,i have to specify the primarykey class type,which i am missing out and hence getting the error.
    Please help me out with your advice and solution.
    Thanks
    Rahul Priyadarshi

    Hi,
    Sorry to disturb you again.
    Even my code is also almost the same....i am pasting the code below...Please go through it and let me know if I have made any mistake..
    EditVendorEntityBean.....(Bean Class)
    package code.beans.EditVendor;
    import code.beans.dataAccess.*;
    import javax.ejb.CreateException;
    import javax.ejb.RemoveException;
    import javax.ejb.EntityBean;
    import javax.ejb.EntityContext;
    import javax.ejb.EJBException;
    import javax.ejb.FinderException;
    import javax.ejb.ObjectNotFoundException;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.sql.*;
    import javax.sql.*;
    import java.util.*;
    * Bean implementation class for Enterprise Bean: EditVendorEntity
    public class EditVendorEntityBean implements javax.ejb.EntityBean {
         private static Hashtable dataSources = new Hashtable();
         private String username;
    private int Vendor_ID;
    private int Category_Id;
    private String Category_Name;
    private String Vendor_Name;
    private String Vendor_Address1;
    private String Vendor_Address2;
    private String Contact_Name;
    private String Home_Phone;
    private String Work_Phone;
    private String email;
    private String faxno;
    private String userloginname;
    private boolean dirtyFlag = false;
    private EntityContext context;
    private static final String DS_NAME = "jdbc/spiPOPS";
    Connection con = null;
    Statement stmt = null;
    PreparedStatement st = null;
    ResultSet res = null;
         //***********************Business Methods*********************
    // Begin of Busines Methods
    public void setData (String[] catname, String vendorname,String vendadd1,String vendadd2,String vendcontact,String venoff,String venres,String mailid,String venfax) {
              System.out.println("in setData where Vendor Id= "+ Vendor_ID);
                   boolean status=false;
                   boolean existing=false;
                   ArrayList cat=new ArrayList();
                   try
                        cat=getcategorylist(this.Vendor_ID);
                   catch(SQLException e)
                        System.out.println("Could not get category list");
                   System.out.println("Size of cat array -->" + cat.size() + " and string array size -->" + catname.length);
                   if(catname.length>0)
                        //Removing unwanted vendor categories for a particular vendor id
                        for(int i=0;i<cat.size();i++)
                                  existing=false;
                                  String tempdata=(String)cat.get(i);
                                  for(int j=0;j<catname.length;j++)
                                       if(tempdata.equals(catname[j]))
                                            existing=true;
                                  if(!existing)
                                       try
                                            delvencat(this.Vendor_ID,tempdata.trim());
                                       catch(SQLException e)
                                            System.out.println("Could not delete record in POPS_VENDOR_CATEGORY for -->" + tempdata);
                   //Adding new vendor categories for a particular vendor
                        try
                                  for(int i=0;i<catname.length;i++)
                                       status=false;
                                       String strcat=catname;
                                       status=checkcat(this.Vendor_ID,strcat.trim());
                                       if(!status)
                                            insertvencat(this.Vendor_ID,strcat.trim());
                        catch(SQLException e)
                                  System.out.println("Could not insert or select from POPS_VENDOR_CATEGORY table");
                   this.Vendor_Name          =vendorname;
              this.Vendor_Address1     =vendadd1;
              this.Vendor_Address2     =vendadd2;
              this.Contact_Name          =vendcontact;
              this.Work_Phone               =venoff;
              this.Home_Phone               =venres;
              this.email                    =mailid;
              this.faxno                    =venfax;
                   dirtyFlag = true;
                   System.out.println("Leaving set data method");
    public Vector getData() {
         Vector vctRec=new Vector();
         ArrayList arrdatas = new ArrayList();
         arrdatas.add(""+this.Vendor_ID);
         arrdatas.add(this.Vendor_Name);
         arrdatas.add(this.Vendor_Address1);
         arrdatas.add(this.Vendor_Address2);
         arrdatas.add(this.Contact_Name);
         arrdatas.add(this.Work_Phone);
         arrdatas.add(this.Home_Phone);
         arrdatas.add(this.email);
         arrdatas.add(this.faxno);
         vctRec.addElement(arrdatas);
         ArrayList cat=new ArrayList();
              try
              System.out.println("Calling getcategorylist from getdata with vendorid-->" + this.Vendor_ID);
              cat          = getcategorylist(this.Vendor_ID);
         catch(SQLException e)
                   System.out.println("Could not get datas for category list");
         vctRec.addElement(cat);
         ArrayList allcats=new ArrayList();
         try
                        allcats          = getallcategorylist();
              catch(SQLException e)
                        System.out.println("Could not get datas for category list");
         vctRec.addElement(allcats);
              dirtyFlag = false;
         System.out.println("Before return statement in getdata with vector size -->" + vctRec.size());
              return vctRec;
    // End of Business Methods
    //**************************Entity Bean Methods*******************************
         * ejbActivate
         public void ejbActivate() {
              Vendor_ID = Integer.parseInt((String)context.getPrimaryKey());
         System.out.println("Inside ejbActivate Vendor_ID-->"+ Vendor_ID);
         * ejbLoad
         public void ejbLoad() {
              System.out.println("Inside ejbLoad ********" );
    try {
    loadRow();
    }catch (Exception ex) {
              System.out.println("Failed in loadRow()");
    throw new EJBException("ejbLoad: " +
    ex.getMessage());
         * ejbPassivate
         public void ejbPassivate() {
         System.out.println("Inside ejbPassivate " );
    Vendor_ID = 0;
         * ejbRemove
         public void ejbRemove() throws javax.ejb.RemoveException {
              //Empty Method
         * ejbStore
         public void ejbStore() {
    System.out.println("Inside ejbStore " );
    try {
    storeRow();
    }catch (Exception ex) {
              System.out.println("Exception thrown in storeRow" + ex.getMessage());
    throw new EJBException("ejbLoad: " +
    ex.getMessage());
         * getEntityContext
         public javax.ejb.EntityContext getEntityContext() {
              return context;
         * setEntityContext
         public void setEntityContext(javax.ejb.EntityContext ctx) {
              System.out.println("Inside setEntityContext " );
    try{
         con = getConnection(DS_NAME);
         System.out.println("DB Connection Created!!");
    catch(Exception e){
    this.context = ctx;
         * unsetEntityContext
         public void unsetEntityContext() {
    System.out.println("Inside unsetEntityContext " );
    closeDbConnection(con, res, st);
    this.context = null;
         * ejbCreate
         //code.beans.EditVendor.EditVendorEntityKey
         public code.beans.EditVendor.EditVendorEntityKey ejbCreate(String vendorid)
              throws javax.ejb.CreateException {          
              return new EditVendorEntityKey(vendorid);
              //return null;
         * ejbPostCreate
         public void ejbPostCreate(String vendorid) throws javax.ejb.CreateException {
              //Empty
         * ejbFindByPrimaryKey
         //code.beans.EditVendor.EditVendorEntityKey
         public code.beans.EditVendor.EditVendorEntityKey ejbFindByPrimaryKey(
              code.beans.EditVendor.EditVendorEntityKey primaryKey)
              throws javax.ejb.FinderException {
    try {
    if(selectByPrimaryKey(Integer.parseInt(primaryKey.getVendorId()))) {
              System.out.println("Leaving the findbyprimarykey method from the entity bean");
         return primaryKey;
         //return null;
    }else {
         throw new ObjectNotFoundException
         ("Row for id " + primaryKey + " not found.");
    }catch (Exception ex) {
    throw new EJBException("EXCEPTION IN ejbFindByPrimaryKey :- " + ex.getMessage());
         /*********************** Database Utility Routines *************************/
    private boolean selectByPrimaryKey(int priKey)
    throws SQLException {
         System.out.println("inside selectByPrimaryKey for primary key " + priKey);
    String queryStr ="SELECT VENDOR_ID FROM POPS_VENDOR WHERE VENDOR_ID = " + priKey;
    System.out.println("in selectByPrimaryKey where queryString is: "+ queryStr);
              stmt = con.createStatement();
    ResultSet result = stmt.executeQuery(queryStr);
    if(!result.next()) {
    stmt.close();
         System.out.println("Did not find "+priKey);
    return false;
    else { //Found the primaryKey
    Vendor_ID = result.getInt("VENDOR_ID");
    stmt.close();
    return true;
    private void loadRow() throws SQLException {
              System.out.println("inside loadRow ...");
              stmt = con.createStatement();
              String queryStr = "SELECT VENDOR_NAME,VENDOR_ADDRESS1,VENDOR_ADDRESS2,CONTACT_NAME,HOME_PHONE,WORK_PHONE,EMAIL_ID,FAX_NO " +
                                  "FROM POPS_VENDOR WHERE VENDOR_ID=" + Vendor_ID;
              System.out.println("Inside loadRow()***********"+queryStr);
              ResultSet result = stmt.executeQuery(queryStr);
              ArrayList catadatas=new ArrayList();
         if(!result.next())
         throw new SQLException("No record for primary key" + Vendor_ID);
              this.Vendor_ID               =Vendor_ID;
                        this.Vendor_Name          =result.getString("VENDOR_NAME");
                        this.Vendor_Address1     =result.getString("VENDOR_ADDRESS1");
                        this.Vendor_Address2     =result.getString("VENDOR_ADDRESS2");
                        this.Contact_Name          =result.getString("CONTACT_NAME");
                        this.Home_Phone               =result.getString("HOME_PHONE");
                        this.Work_Phone               =result.getString("WORK_PHONE");
                        this.email                    =result.getString("EMAIL_ID");
                        this.faxno                    =result.getString("FAX_NO");
                             System.out.println("Leaving loadrow method with loaded datas for vendor -->" + Vendor_ID);
                             stmt.close();
    private ArrayList getcategorylist(int vendor) throws SQLException{
              String queryStr ="SELECT DISTINCT(VENDOR_CAT) FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID=" + vendor;
              System.out.println("Query for the cat list --> " + queryStr);
              stmt = con.createStatement();
              ResultSet result = stmt.executeQuery(queryStr);
              ArrayList catdatas=new ArrayList();
    try{
                   while(result.next())
                        catdatas.add(result.getString("VENDOR_CAT"));
              catch (SQLException e){
                   stmt.close();
                   System.out.println("Could not retrieve datas for Category list");
              stmt.close();
              System.out.println("size off array for cat -->" + catdatas.size() + " and datas ->" + catdatas);
              return catdatas;
         private ArrayList getallcategorylist() throws SQLException{
                   //String queryStr ="SELECT DISTINCT(VENDOR_CAT) FROM POPS_VENDOR_CATEGORY";
                   StringBuffer strquery=new StringBuffer(20);
                   strquery.append("SELECT DISTINCT(CATEGORY_NAME) FROM POPS_CATEGORY");
                   stmt = con.createStatement();
                   //ResultSet result = stmt.executeQuery(queryStr);
                   ResultSet result = stmt.executeQuery(strquery.toString());
                   ArrayList catdatas=new ArrayList();
                   try{
                        while(result.next())
                                  //catdatas.add(result.getString("VENDOR_CAT"));
                                  catdatas.add(result.getString("CATEGORY_NAME"));
                   catch (SQLException e){
                             stmt.close();
                             System.out.println("Could not retrieve datas for All Category list");
                   stmt.close();
                   return catdatas;
         private void delvencat(int vendor,String vencat) throws SQLException {
              int update=-1;
              stmt = con.createStatement();
              String queryStr ="DELETE FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID = " + vendor + " AND VENDOR_CAT = '" + vencat.toUpperCase() + "'";
              System.out.println("Delete query --> " + queryStr);
              update= stmt.executeUpdate(queryStr);
              if(update!=1)
                   System.out.println("Did not find data to delete");
              stmt.close();
         private void insertvencat(int vendor,String vencat) throws SQLException {
              int update=-1;
              String queryStr ="INSERT INTO POPS_VENDOR_CATEGORY(VENDOR_ID,VENDOR_CAT)" +
                                  " VALUES(" + vendor +",'" + vencat + "')";
              System.out.println("Insert query --> " + queryStr);
              stmt = con.createStatement();
              update=stmt.executeUpdate(queryStr);
              if(update!=1)
                   System.out.println("Could not insert records in the database");
              stmt.close();
         private boolean checkcat(int vendor,String catven) throws SQLException {
              boolean datastatus=false;
              String queryStr ="SELECT VENDOR_ID FROM POPS_VENDOR_CATEGORY WHERE VENDOR_ID = " + vendor + " AND VENDOR_CAT = '" + catven.toUpperCase() + "'";
              stmt = con.createStatement();
              ResultSet result = stmt.executeQuery(queryStr);
              datastatus=result.next();
              stmt.close();
              return datastatus;
    private void storeRow() throws SQLException {
                   System.out.println("Inside ejb store");
         if (!dirtyFlag) {
         System.out.println("Skipping the UPDATE because object is not dirty");
         return;
         CallableStatement cs=null;
    try{
                        cs = con.prepareCall("EXEC POPS_VENDOR_UPDATE " + this.Vendor_ID + ",'" + this.Vendor_Name + "','" + this.Vendor_Address1 + "','" + this.Vendor_Address2 + "','" + this.Contact_Name + "','" + this.Work_Phone + "','" + this.Home_Phone + "','" + this.email + "','" + this.faxno +"'");
                        System.out.println("\n\n SQL Statement : \n " + "EXEC POPS_VENDOR_UPDATE " + this.Vendor_ID + ",'" + this.Vendor_Name + "','" + this.Vendor_Address1 + "','" + this.Vendor_Address2 + "','" + this.Contact_Name + "','" + this.Work_Phone + "','" + this.Home_Phone + "','" + this.email + "','" + this.faxno +"'");
                        cs.executeUpdate();
              catch (SQLException e){
                        cs.close();
                        System.out.     println("\n\n Error in calling stored procedure POPS_INSERT_NEW_REQUEST \n\n"+ e.getMessage() + "\n\n");
              cs.close();
              dirtyFlag = false;
         private Connection getConnection(String dbName) throws SQLException
              String configuredDataSourceName = null;
              if (dbName == null) {
                   System.out.println("Attemp to get connection failed. The requested database name is null");
              DataSource dbSource = getDataSource(dbName);
              return dbSource.getConnection();
         private DataSource getDataSource(String dbName)
              // looking from cache;
              DataSource dbSource = (DataSource) dataSources.get(dbName);
              if (dbSource == null) { //we need to find it from JNDI
                   try {
                        Context ic = new InitialContext();
                        dbSource = (DataSource) ic.lookup(dbName);
                        dataSources.put(dbName, dbSource);
                   }catch (NamingException e){
              return dbSource;
         * User calls this function to safely close an connection
         * @param connt The connection a datasource
         * @param rs The resulSet inside this connection
         * @param statement The statement associate with this connection
         private void closeDbConnection(Connection cont,ResultSet rs,Statement statement)
              if (rs != null)
              try {
                        rs.close();
                   } catch (SQLException ignored) {
                        ignored.printStackTrace();
              if (statement != null)
                   try {
                        statement.close();
                   } catch (SQLException ignored) {
                        ignored.printStackTrace();
              if (cont != null)
                   try {
                        cont.close();
                   } catch (SQLException ignored) {
                        ignored.printStackTrace();
         } //closeDbConnection
    EditVendorEntity (Remote Interface)
    package code.beans.EditVendor;
    import javax.ejb.EJBObject;
    import java.rmi.RemoteException;
    import java.util.*;
    * Remote interface for Enterprise Bean: EditVendorEntity
    public interface EditVendorEntity extends javax.ejb.EJBObject {
         public void setData (String[] catname, String vendorname,String vendadd1,String vendadd2,String vendcontact,String venoff,String venres,String mailid,String venfax)
                   throws RemoteException;
    public Vector getData() throws RemoteException;
    EditVendorEntityHome (Home Interface)
    package code.beans.EditVendor;
    import java.rmi.RemoteException;
    import javax.ejb.CreateException;
    import javax.ejb.FinderException;
    import javax.ejb.DuplicateKeyException;
    import javax.ejb.EJBHome;
    import java.util.*;
    * Home interface for Enterprise Bean: EditVendorEntity
    public interface EditVendorEntityHome extends javax.ejb.EJBHome {
         * Creates an instance from a key for Entity Bean: EditVendorEntity
         public code.beans.EditVendor.EditVendorEntity create(String vendorid)
              throws javax.ejb.CreateException, java.rmi.RemoteException;
         * Finds an instance using a key for Entity Bean: EditVendorEntity
         public code.beans.EditVendor.EditVendorEntity findByPrimaryKey(
              code.beans.EditVendor.EditVendorEntityKey Vendor_ID)
              throws javax.ejb.FinderException, java.rmi.RemoteException;
    EditVendorEntityKey (Primary Key Class)
    package code.beans.EditVendor;
    * Key class for Entity Bean: EditVendorEntity
    public class EditVendorEntityKey implements java.io.Serializable {
         static final long serialVersionUID = 3206093459760846163L;
         public String primkey;
         * Creates an empty key for Entity Bean: EditVendorEntity
         public EditVendorEntityKey() {  }
         public EditVendorEntityKey(String primarykey) {     
              this.primkey=primarykey;
         public String getVendorId() {
    return primkey;
         * Returns true if both keys are equal.
         public boolean equals(java.lang.Object otherKey) {
              if (otherKey instanceof code.beans.EditVendor.EditVendorEntityKey) {
                   code.beans.EditVendor.EditVendorEntityKey o =
                        (code.beans.EditVendor.EditVendorEntityKey) otherKey;
                   return (primkey.equals(otherKey));
              return false;
         * Returns the hash code for the key.
         public int hashCode() {
              return (primkey.hashCode());
    Please go through and give me your comments and solution...
    Thanks in advance
    Rahul

  • Question on Persistence (Entity Beans, Hibernate, JDBC)

    Hi everybody!
    Until now, I have read a lot about persistence in the J2EE-sector, but I am still confused about which technology to used in my case.
    I hope, that maybe you can give me some hints, by telling me which technology is good or bad regarding my requirements:
    I want to build a customer- and order-management system fullfilling the following requirements:
    1. The client is a Java application, the server is a JBOSS 4.0.1
    2. The databasa scheme exists already and I'm not allowed to change it.
    Some data, that logically belongs together and which shall be presented together to the client is distributed over 2 database tables.
    3. The user cannot just create new and view data, but will also edit existing data quite often.
    4. The user can assign products to an order. Often, there will be more than 1000 products assigned to an order, which will be presented to the user as a table (e.g. JTable). The user can then edit each cell of that 1000-row table, which of course will lead to an update in the db.
    5. The user can also assign customers to a specific role in an order-process. On the other hand, each customer can make many orders.
    So, we have a n:m relation here with the db-tables Customer, Order, OrderCustomer.
    6. A complex search functionality has to be implemented, where the db-query is created dynamically at runtime.
    7. The application is a multi-user application (about 10 users). It will be very rare, that users will work on the same data at the same time, but it might happen.
    8. The database type (SAP DB) will not be changed in the near future.
    With these 8 requirements in mind, I dealed a lot with EntityBeans, Hibernate and JDBC with SesseionBeans during the last 2 weeks.
    Until now, I came to the following conclusions.
    Hibernate is too slow. That'S bad, for data is edited very often and sometimes I want to edit just a single cell in 1000-row table.
    Hibernate's biggest advantage - that it makes your application independent of the database type - is not even required (see point 8).
    JDBC with SessioBeans: Very fast (I tried a simple query and it was about 10 times faster than Hibernate).
    The disadvantage is, that I have to take care about all the transaction, concurrency control etc. things.
    If I use JDBC, I want to do it that way: A SessionFacade accesses a DAO-object which executes the DB-query and returns the result to the SessionFacade which in the last step will pass the result to the client.
    Entity Beans: I am completely confused with Entity Beans.
    I read a lot about the CompositeEntity-Pattern for BMP. But on sun's J2EE Pattern page (http://java.sun.com/blueprints/corej2eepatterns/Patterns/CompositeEntity.html)
    they said, that it's just useful when using the EJB 1.1 specification, because from EJB 2.0. the container or whatever will take care about lazy loading and store optimization.
    So, from EJB 2.0. you should prefer using CMP-Beans with Container Managed Relationships (CMR), but as I heard, the dependent objects cannot be accessed and changed by the client when using CMPBeans with CMR.
    However, a simple DB/Entity-mapping will not work in my case, because as mentioned above, there are thousands of products from the db to be managed at the same time. So here, I thought, the Composite pattern with its lazy loading strategy would be useful.
    Furthermore, I have an n:m relationship in my database scheme, which is not trivial to map to entity beans. And don't forget that some related data is spread over 2 databse tables.
    To sum it up, it would be very nice if some of you could clarify this perisistence nightmare, especially some clarification about if and how to use EntityBeans when having n:m relationships, editing data a lot, managing lots of table rows at once and having related data distributed over 2 database tables.
    So, which technology would you prefer with the 8 requirements in mind? Hibernate, Entity Beans or JDBC with SessionBeans? Or would you prefer a mixed solution?
    Thanx for every hint.
    Regards,
    egon

    Here the requested information about the test:
    Goal:
    Find all customers, who's branches have the String "Branch" in their name.
    Both times, a simple client accesses the same SessionBean in a JBOSS-Container.
    This Bean has 2 methods. One accesses the DB via Hibernate (executeCriteria), the other one via JDBC (executeCriteriaJDBC).
    The code to count the seconds of computation is as follows:
    long startTime = System.currentTimeMillis();
    List customerList = bean.executeCriteria(dc);
    System.out.println("Hibernate: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
    startTime = System.currentTimeMillis();
    List customerListJDBC = bean.executeCriteriaJDBC(query);
    System.out.println("JDBC: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
    HIBERNATE:
    CODE:
    Branch Branch = new Branch();
    Branch.setName("%Branch%");
    Example example = Example.create(Branch);     
    DetachedCriteria dc = DetachedCriteria.forClass(Customer.class)
    .createCriteria("branches").add(example.enableLike()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    QUERY:
    select
            this_.UUID as UUID1_1_,
            this_.NAME as NAME1_1_,
            this_.CUSTOMERNO as CUSTOMERNO1_1_,
            this_.SHORTDESC as SHORTDESC1_1_,
            this_.LONGDESC as LONGDESC1_1_,
            this_.TAXNUMBER as TAXNUMBER1_1_,
            this_.SALESTAXID as SALESTAXID1_1_,
            this_.ACCOUNTHOLDER as ACCOUNTH8_1_1_,
            this_.BANKACCOUNT as BANKACCO9_1_1_,
            this_.BANKCODE as BANKCODE1_1_,
            this_.BANKNAME as BANKNAME1_1_,
            this_.AREA1TEXT as AREA12_1_1_,
            this_.AREA2TEXT as AREA13_1_1_,
            this_.AREA3TEXT as AREA14_1_1_,
            this_.AREA4TEXT as AREA15_1_1_,
            this_.AREA5TEXT as AREA16_1_1_,
            this_.CH_UUID as CH17_1_1_,
            this_.REFTEXT1 as REFTEXT18_1_1_,
            this_.REFTEXT2 as REFTEXT19_1_1_,
            this_.REFTEXT3 as REFTEXT20_1_1_,
            branch1_.UUID as UUID0_0_,
            branch1_.NAME as NAME0_0_,
            branch1_.ILN as ILN0_0_,
            branch1_.BRANCHID as BRANCHID0_0_,
            branch1_.SHORTDESC as SHORTDESC0_0_,
            branch1_.LONGDESC as LONGDESC0_0_,
            branch1_.BAGSRECEIVED as BAGSRECE7_0_0_,
            branch1_.CUSTOMER_UUID as CUSTOMER8_0_0_
        from
            CUSTOMER this_,
            BRANCH branch1_
        where
            this_.UUID=branch1_.CUSTOMER_UUID
            and (
                branch1_.NAME like ?
    RESULT:
    Customername: Customer_A
    Customername: Customer_F
    Customername: Customer_D
    Customername: Customer_R
    Customername: Customer_S
    TIME:
    Hibernate: 1.343 sek
    JDBC:
    QUERY:
    Select distinct c.* from Customer c, Branch b where b.id=b.Customer_id and b.name like '%Branch%'
    // After getting the result of the query: Create a list of Customer-objects. Set all attributes of each Customer-object.
    RESULT:
    Customername: Customer_R
    Customername: Customer_A
    Customername: Customer_S
    Customername: Customer_D
    Customername: Customer_F
    TIME:
    JDBC: 0.125 sek
    The Customer.hbm.xml (auto-generated in Eclipse with Middlegen)
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
    <hibernate-mapping>
    <!--
        Created by the Middlegen Hibernate plugin 2.2
        http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    -->
    <class
        name="hibernate.hibernate.Customer"
        table="CUSTOMER"
        lazy="false"
    >
        <id
            name="uuid"
            type="java.lang.String"
            column="UUID"
        >
            <generator class="assigned" />
        </id>
        <property
            name="name"
            type="java.lang.String"
            column="NAME"
            length="100"
        />
        <property
            name="customerno"
            type="java.lang.Integer"
            column="CUSTOMERNO"
            length="5"
        />
        <property
            name="shortdesc"
            type="java.lang.String"
            column="SHORTDESC"
            length="50"
        />
        <property
            name="longdesc"
            type="java.lang.String"
            column="LONGDESC"
            length="100"
        />
        <property
            name="taxnumber"
            type="java.lang.String"
            column="TAXNUMBER"
            length="50"
        />
        <property
            name="salestaxid"
            type="java.lang.String"
            column="SALESTAXID"
            length="50"
        />
        <property
            name="accountholder"
            type="java.lang.String"
            column="ACCOUNTHOLDER"
            length="50"
        />
        <property
            name="bankaccount"
            type="java.lang.String"
            column="BANKACCOUNT"
            length="50"
        />
        <property
            name="bankcode"
            type="java.lang.String"
            column="BANKCODE"
            length="50"
        />
        <property
            name="bankname"
            type="java.lang.String"
            column="BANKNAME"
            length="50"
        />
        <property
            name="area1text"
            type="java.lang.String"
            column="AREA1TEXT"
            length="50"
        />
        <property
            name="area2text"
            type="java.lang.String"
            column="AREA2TEXT"
            length="50"
        />
        <property
            name="area3text"
            type="java.lang.String"
            column="AREA3TEXT"
            length="50"
        />
        <property
            name="area4text"
            type="java.lang.String"
            column="AREA4TEXT"
            length="50"
        />
        <property
            name="area5text"
            type="java.lang.String"
            column="AREA5TEXT"
            length="50"
        />
        <property
            name="chUuid"
            type="java.lang.String"
            column="CH_UUID"
            length="50"
        />
        <property
            name="reftext1"
            type="java.lang.String"
            column="REFTEXT1"
            length="50"
        />
        <property
            name="reftext2"
            type="java.lang.String"
            column="REFTEXT2"
            length="50"
        />
        <property
            name="reftext3"
            type="java.lang.String"
            column="REFTEXT3"
            length="50"
        />
        <!-- Associations -->
        <!-- bi-directional one-to-many association to Branch -->
        <set
            name="branches"
            lazy="true"
            inverse="true"
           cascade="all"
        >
            <key>
                <column name="CUSTOMER_UUID" />
            </key>
            <one-to-many
                class="hibernate.hibernate.Branch"
            />
        </set>
    </class>
    </hibernate-mapping>So, seems to me like Hibernate is also getting the data from the Branch-Table related to each Customer. Maybe this is the reason, why Hibernate is slower.
    But as you can see in the mapping-File of the customer, I wanted Branches to be lazy loaded.
    Do you have any ideas, why Hibernate is so much slower? Any hints for optimizing that code?
    Do you have any further tricks to optimize Hibernate? Unfortunately I am not allowed to make changes at the database, so I cannot e.g. set indices for optimization.
    However, I�m a Hibernate-Newbie. In fact, I just made this test and was very disappointed about its result, so I didn�t keep on working with Hibernate.
    But maybe you can proof me, that Hibernate is a good choice. If so, do you have any good resources (links, books) that help working with Hibernate in connection with JBOSS, describe how to map n:m relationships, show how to work with large results and so forth?
    Thanx for help,
    egon

Maybe you are looking for