Finder  method in Entity bean

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

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

Similar Messages

  • Multiple create methods of entity beans in single transcation

    Hi,
    I have some entity beans with CMR. I am managing these entity beans with a Stateful session bean whose transaction type is Container Managed for all its methods.
    In one particular method of this Session bean I am calling two entity bean's create method. i.e I am creating two entity beans through home.create() methods. There are two home.create() methods one after another inside a try catch block.
    I want that the entire operation be under just one transcation so i have also given the transaction attribute as Required for all methods of Session bean and Entity Beans.
    However if i pass invalid parameters to second create method so that it generates exception then still the first create statement is successful and database is updated.
    what i want is that the first create also should be roll backed.
    How can i acheive this through Container Managed Transaction Session Bean?

    Hi Ashwini,
    "Ashwini" <[email protected]> wrote in message news:400291af$[email protected]..
    I have some entity beans with CMR. I am managing these entity beans with a Stateful session bean whose transactiontype is Container Managed for all its methods.
    >
    In one particular method of this Session bean I am calling two entity bean's create method. i.e I am creatingtwo entity beans through home.create() methods. There are two home.create() methods one after another inside a try catch
    block.
    >
    I want that the entire operation be under just one transcation so i have also given the transaction attribute asRequired for all methods of Session bean and Entity Beans.
    >
    However if i pass invalid parameters to second create method so that it generates exception then still the firstcreate statement is successful and database is updated.
    what i want is that the first create also should be roll backed.
    How can i acheive this through Container Managed Transaction Session Bean?o Do you use TXDatasource with your entity beans?
    o In CMT transactions are automatically rolled back only when RuntimeExceptions
    are thrown. What kind of exception is thrown in your case?
    Regards,
    Slava Imeshev

  • Finder methods for CMP beans

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

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

  • MDB gets cannot find recently created Entity Bean

    I have a session bean that creates several entities beans, and puts a message onto
    JMS queue. A MDB is configured to read the queue, and in onMessage(), it calls
    findByPrimaryKey() for one of the newly created EntityBeans. However, the entity
    bean cannot be found.
    All of the beans in question are using container managed transactions, and all
    have transaction required. The entity bean that I'm looking for is using optimistic
    concurrency. I cannot change it to exclusive without redesigning a major part
    of the system, which have solved a similar problem that I encounted earlier that
    did not involve any message driven beans.
    The only way that I got it to work is put in Thread.sleep(5000) right before calling
    the finder. Does anyone know of any alternatives besides having the MDB sleep?

    No, this will work fine with the existing server. If the publish is
    part of the JTA transaction, then no one can consume the message until
    the original JTA transaction has committed.
    -- Rob
    Rajesh Mirchandani wrote:
    XA defines that a transaction's individual operations will either fail or
    succeed atomically. XA can not, and does not define that a transaction's
    individual operations occur exactly simultaneously.
    The WL transaction monitor does not currently provide a way to serialize a
    transactions commit operations on its component resource managers.
    There is an enhancement filed for this, I guess. Follow up with BEA support.
    Rob Woollen wrote:
    Vina Wang wrote:
    The JMS send is part of the transaction, sort of. The call is within
    the session
    bean transaction, but I'm not using transacted session for
    JMSPulisher. Would
    that fix the problem?Sadly this is a confusing aspect of JMS. You want a non-transacted
    session because you want it to participate in the global transaction
    that the EJB started. Also, make sure that you've enabled user
    transactions on your connection factory.
    There's more info here:
    http://edocs.bea.com/wls/docs70/faq/jms.html#252635
    Let us know if you're still having problems.
    -- Rob
    I know that the transaction hasn't been commited, but I was monitoring
    database
    via SQL call when I tried this. There was about 2 second delay on my
    development
    machine.
    Rob Woollen wrote:
    My guess is the MDB is receiving the message before your "create entity
    bean" transaction has committed. Is the JMS send part of the "create
    entity bean" transaction? It probably should be.
    You can easily prove this by writing a few lines of JDBC to hit the
    database and check for your primary key.
    I would not recommend changing to exclusive or using the Thread.sleep.
    -- Rob
    Vina Wang wrote:
    I have a session bean that creates several entities beans, and putsa
    message onto
    JMS queue. A MDB is configured to read the queue, and in onMessage(),
    it calls
    findByPrimaryKey() for one of the newly created EntityBeans. However,
    the entity
    bean cannot be found.
    All of the beans in question are using container managed transactions,
    and all
    have transaction required. The entity bean that I'm looking for is
    using optimistic
    concurrency. I cannot change it to exclusive without redesigning a
    major part
    of the system, which have solved a similar problem that I encounted
    earlier that
    did not involve any message driven beans.
    The only way that I got it to work is put in Thread.sleep(5000) right
    before calling
    the finder. Does anyone know of any alternatives besides having the
    MDB sleep?
    Rajesh Mirchandani
    Developer Relations Engineer
    BEA Support

  • Using wildcards in custom find methods with CMP beans

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

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

  • Binary Data Type in finder methods for CMP beans

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

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

  • Calling Stateful & Statless Methods from the same Entity Bean[EJB2.0]?

    Dear All,
    We using EJB2.0........
    Regarding segregation of stateless and stateful methods..These methods are defined in Session bean.Now my question is
    Is it a good practice to call Stateful and Stateless business methods from same single entity bean("EntityBean") defined at program level by extending MainBean..
    The architecture is like
    public class EntityBean extends MainBean
    Public Methodxyz
    stfobj.MakeConn();
    stlobj.getXyz();
    stfobj.CloseConn();
    Public Class MainBean{lookup("stl");lookup(stf) ;stl_obj=home.create;stf_obj=home.create()............}
    ejb-jar.xml
    { <session>
              <description>Entity Bean Employee Example</description>
              <ejb-name>stl</ejb-name>
              <local-home>com.packg.stlHome</local-home>
              <local>com.packg.stl</local>
              <ejb-class>com.packg.stlBean</ejb-class>
              <session-type>Stateless</session-type>
              <transaction-type>Container</transaction-type>
         </session>
         <session>
              <description>Entity Bean Employee Example for stateful</description>
              <ejb-name>stf</ejb-name>
              <local-home>com.packg.stfHome</local-home>
              <local>com.packg.ejbeans.stf</local>
              <ejb-class>com.packg.stfBean</ejb-class>
              <session-type>Stateful</session-type>
              <transaction-type>Container</transaction-type>
         </session>
         <session>
              <description>Session bean for System Parameters</description>
              <ejb-name>SysParam</ejb-name>
              <local-home>com.packg.Home</local-home>
              <local>com.packg.Param</local>
              <ejb-class>com.packg.Bean</ejb-class>
              <session-type>Stateless</session-type>
              <transaction-type>Bean</transaction-type>
              <ejb-local-ref>
              <ejb-ref-name>stl</ejb-ref-name>
              <ejb-ref-type>Session</ejb-ref-type>
              <local-home>com.packg.stlHome</local-home>
              <local>com.packg.ejbeans.stl</local>
              <ejb-link>stl</ejb-link>
         </ejb-local-ref>
              <ejb-local-ref>
              <ejb-ref-name>stf</ejb-ref-name>
              <ejb-ref-type>Session</ejb-ref-type>
              <local-home>com.packg.stfHome</local-home>
              <local>com.packg.stf</local>
              <ejb-link>stf</ejb-link>
         </ejb-local-ref>
         </session>
    Thanks !!
    Edited by: user9052593 on Jun 18, 2012 2:20 AM
    Edited by: user9052593 on Jun 18, 2012 2:25 AM

    All Business logic resides in session beans[Stateful or Stateless]..For stateful beans we are opening connections in entity bean ,calling business methods and closing connection in entity bean itself..Problem is
    I am doing lookup for stateful and stateless both since both objects are called by extending MainBean in same entity bean else will give null pointer exception..
    So whenever i call a Stateful or Stateless method from entity bean Which ultimately extends/calling MainBean and thereby calling home.create methods of stateful and stateless both..creating objects..Is this way fine or it will affect the performance?
    Do i need to segregate the Calls/invokation to Stateful / Stateless methods at entity bean level too..
    For ex:- Whenever i call Methodxyz() method ..at the same time it create 2 objects as its extending MainBean...i want to extend/create 1 object either of stateful or stateless one for stateful and stateless methods call respectively..
    See the code in entity bean is like
    public class EntityBean extends MainBean
    Public Methodxyz
    stfobj.MakeConn(); call to stateful method defined in stateful bean
    stlobj.getXyz();// call to stateless method defined in stateless bean
    stfobj.CloseConn(); call to stateful method defined in stateful bean
    ------------------------------------------------------------

  • Exposing local entity beans to web tier?

    Hello all,
    I have a question concerning basic design issues with EJB and the JSP presentation
    layer. Currently, I have designed a system using all local component interfaces
    of EJB 2.0. I currently have the following architecture in place:
    EJB --> Servlets (WebWork Actions) --> JSP
    I'm utilizing the session facade design pattern where the business logic in encapsulated
    in session beans, which internally access the entity beans, etc. However, I am
    doing something of the following:
    sessionBean.getUserAccounts() which returns a Collection of actual UserAcountLocal's.
    I then am passing this collection off to the JSP just to cycle through each entity
    bean and display the data via its getXXX() methods. No modifications to the entity
    beans are being done directly in the Actions/JSPs, rather they are modified through
    methods of the session beans. Now I know that there is the concept of DTO (Data
    transfer objects), which send the data from the particular entity bean to a regular
    java bean for presentation. I know that DTO's increase performance if one is using
    remote interfaces, because there is less network traffic that occurs via that
    transport method. However, I know that WebLogic performs excellent caching of
    entity beans, so that multiple invocations of get() methods on entity beans will
    not make a trip to the database each and every time the get() method is called.
    So, my question is: Is it "safe" to continue with the current way I am designing/coding
    the system? I just find it a bit tedious to create value objects for each and
    every entity bean, if I know that I will not be calling setXXX() methods from
    within the presentation layer. Also, with EJB 2.0 and the introduction of local
    component interfaces, it seems that issues regarding limiting the amount of network
    traffic don't seem to be so relevant. Any suggestions/tips are appreciated. :-)
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669

    use dtos
    the main reason is that if you call a getXXX() method on a local or remote
    interface from your servlet then that bean is retrieved again (as the
    servlet is outside the transaction involved in the initial retrieval)
    For example if you retrieve 100 users and want to display them in a html
    table with the user id, first name and lastname then there end up being more
    than 300 SQL statements executed (this is unless your ejbs are readonly)
    If you have a tool (like sql server profiler) that traces sql statements i
    recommend you use it to see the staggering amount of sql statements that are
    being executed by your current code - then DTOs will look much more
    appealing (it worked for me) :).
    I would also recommend using dtos when performing updates. Basically work
    towards your servlets never directly accessing anything entity bean related.
    Some people extend this further and have the DTO as the single argument in
    the create method of an entity bean - I havent done this yet myself but it
    looks like a good idea to me.
    "Ryan LeCompte" <[email protected]> wrote in message
    news:[email protected]...
    >
    Hello all,
    I have a question concerning basic design issues with EJB and the JSPpresentation
    layer. Currently, I have designed a system using all local componentinterfaces
    of EJB 2.0. I currently have the following architecture in place:
    EJB --> Servlets (WebWork Actions) --> JSP
    I'm utilizing the session facade design pattern where the business logicin encapsulated
    in session beans, which internally access the entity beans, etc. However,I am
    doing something of the following:
    sessionBean.getUserAccounts() which returns a Collection of actualUserAcountLocal's.
    I then am passing this collection off to the JSP just to cycle througheach entity
    bean and display the data via its getXXX() methods. No modifications tothe entity
    beans are being done directly in the Actions/JSPs, rather they aremodified through
    methods of the session beans. Now I know that there is the concept of DTO(Data
    transfer objects), which send the data from the particular entity bean toa regular
    java bean for presentation. I know that DTO's increase performance if oneis using
    remote interfaces, because there is less network traffic that occurs viathat
    transport method. However, I know that WebLogic performs excellent cachingof
    entity beans, so that multiple invocations of get() methods on entitybeans will
    not make a trip to the database each and every time the get() method iscalled.
    So, my question is: Is it "safe" to continue with the current way I amdesigning/coding
    the system? I just find it a bit tedious to create value objects for eachand
    every entity bean, if I know that I will not be calling setXXX() methodsfrom
    within the presentation layer. Also, with EJB 2.0 and the introduction oflocal
    component interfaces, it seems that issues regarding limiting the amountof network
    traffic don't seem to be so relevant. Any suggestions/tips areappreciated. :-)
    >
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669

  • Timeout of session / entity bean

    Hi all
    We are facing "RollbackException: The transaction has been marked for rollback (timed out)" excpetion. please help us in resolving this.
    Here is problem description.
    Code Description:
    Step1: Action class calls Session bean
    Step2:Session Bean does three things
    A. Reads various value from database and write it to fileOutputStream
    B. Generate a Sequence number using Sequence
    C. Call create method of Entity Bean by local reference to insert the created file (in step 2A) in database as blob
    As per our observation session bean takes around 20-30 sec in processing 2A and 2B.
    But at 2-C, code raises following error
    TariffDocumentBlob is the Entity Bean
    TariffSessionEJB is the Session Bean
    javax.ejb.CreateException: Error creating EntityBean: RollbackException: The transaction has been marked for rollback (timed out)
    05/10/24 16:04:01      at TariffDocumentBlobLocalHome_EntityHomeWrapper397.create(TariffDocumentBlobLocalHome_EntityHomeWrapper397.java:1135)
    05/10/24 16:04:01      at com.derc.rims.businessservice.businessinterface.TariffSessionEJBBean.createTariffBlobMasterRecord(TariffSessionEJBBean.java:102)
    05/10/24 16:04:01      at com.derc.rims.businessservice.businessinterface.TariffSessionEJBBean.uploadTariff(TariffSessionEJBBean.java:76)
    05/10/24 16:04:01      at TariffSessionEJBLocal_StatelessSessionBeanWrapper96.uploadTariff(TariffSessionEJBLocal_StatelessSessionBeanWrapper96.java:80)
    05/10/24 16:04:01      at com.derc.rims.businessservice.businessinterface.BISessionFacadeEJBBean.delegate(BISessionFacadeEJBBean.java:534)
    05/10/24 16:04:01      at BISessionFacadeEJB_StatelessSessionBeanWrapper4.delegate(BISessionFacadeEJB_StatelessSessionBeanWrapper4.java:101)
    05/10/24 16:04:01      at com.derc.rims.action.tariff.CalculateTariffAction.execute(CalculateTariffAction.java:75)
    05/10/24 16:04:01      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    05/10/24 16:04:01      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    05/10/24 16:04:01      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1485)05/10/24 16:04:01      at
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)05/10/24 16:04:01      at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:760)05/10/24 16:04:01      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)05/10/24 16:04:01      
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)05/10/24 16:04:01      at
    oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)05/10/24 16:04:01      at
    com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)05/10/24 16:04:01      at
    com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)05/10/24 16:04:01 TRANSACTION OVER05/10/24
    16:04:01      at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
    05/10/24 16:04:01      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
    05/10/24 16:04:01      at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    05/10/24 16:04:01      at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    05/10/24 16:04:01      at java.lang.Thread.run(Thread.java:534)
    com.evermind.server.rmi.OrionRemoteException: Transaction was rolled back: timed out     at
    BISessionFacadeEJB_StatelessSessionBeanWrapper4.delegate(BISessionFacadeEJB_StatelessSessionBeanWrapper4.java:159)
    at com.derc.rims.action.tariff.CalculateTariffAction.execute(CalculateTariffAction.java:75)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1485)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
    at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    at java.lang.Thread.run(Thread.java:534)
         Nested exception is:java.rmi.RemoteException: No Exception - originate from:java.lang.Exception: No Exception - originate from:; nested exception is:
         java.lang.Exception: No Exception - originate from:     at com.evermind.server.ejb.EJBUtils.makeException(EJBUtils.java:931)
         at BISessionFacadeEJB_StatelessSessionBeanWrapper4.delegate(BISessionFacadeEJB_StatelessSessionBeanWrapper4.java:159)     
         at com.derc.rims.action.tariff.CalculateTariffAction.execute(CalculateTariffAction.java:75)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1485)     
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)     
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)     
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)     
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)     
         at java.lang.Thread.run(Thread.java:534)
         Caused by: java.lang.Exception: No Exception - originate from:     at com.evermind.server.ejb.EJBUtils.makeException(EJBUtils.java:930)
         ... 17 more
    We have tried out .....
    - Making new Enity Bean
    - changing timeout of session bean by changing it in properties
    <session-deployment name="TariffSessionEJB" timeout="300" >
    We are using Oracle 10g application Sever and Oracle 10.1 database.

    Assuming you are using either 9.0.4 or 10.1.2, please note that default transaction time out is 30s and you can change that <transaction-config> element in server.xml. This is specified in millliseconds
    -Debu

  • Primary key in Entity beans

    Hi
    If my database doesn't have primary key, then how can I define ejbFindByPrimarykey
    method in Entity Beans. ? or in that case can't I use Entity beans. ?
    Pls clear my doubt.
    Thanks in advance

    Ashish,
    If my database doesn't have primary key, then how can I defineejbFindByPrimarykey
    method in Entity Beans. ? or in that case can't I use Entity beans. ?An entity bean instance needs to be uniquely identifiable. That doesn't
    necessarily mean that you have a PK in the database, but those two things do
    usually go together.
    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/
    "Ashish Mangla" <[email protected]> wrote in message
    news:3cf5b304$[email protected]..
    >

  • Entity Beans and Session beans to represet Business lOgic

    How cam we implement Entity Beans and Session beans to represent Business Logic.
    Can anyone explain how can we do this.
    Regards...

    I have session beans calling method in entity beans and any client
    doesn't have access to entity beans, only via session beans.
    If i define security policy and method permissions for session beans
    only, do entity beans use that permissions when calling their methods
    from sessions beans OR should i define the security policy for entity
    beans separately?If you want to set the permission on individual
    methods of entity bean ( with different roles)
    you have to do it separately.
    If you want to delegate the Authenticated user along with
    the method call to the Entity Bean you can use
    run-as-identity-principal.
    For more detail please check out the EJB2.0 Spec.
    -utpal

  • Wrong version of an entity bean object being updated

    We are having a problem with an entity bean that uses bean managed persistence. The "order" entity bean has
    been used as part of our Order Routing System for the last 2 years with no problems. The entity bean is
    accessed via calls from a "Order Manager" session bean. No change has been done to the entity bean but the
    frequency of calls from the session bean to update the entity bean have increased significantly.
    The "order" entity bean wraps an Order object that contains order properties (i.e. id, quantity, price,
    version, etc). The entity bean has a "void setOrder(Order param)" function that writes the Order to a database
    and a "Order getOrder()" function that clones and returns the internal Order object. The "ejbLoad()" function
    reads the Order object from the database and the "ejbStore()" function is not implemented.
    The "OrderEntityPK ejbFindByPrimaryKey()" function checks if the order entity primary key (an "int") exists
    on the database.
    We are using the SilverStream 3.5 application server as our EJB container. According to the SilverStream manual
    it does not maintain a pool of idle/unused entity beans, instead it instantiates beans as requested.
    Our problem is:
    1) The wrong version of the entity object is sometimes being updated (i.e. an old instance of the order entity is being
    picked up and updated on the database).
    2) We sometimes get a TransactionRequired exception thrown when we have concurrent updates to two different
    objects of the entity bean.
    Any idea as to what our problem could be?
    Thanks in advance for your help,
    The following are the main code snippets:
    Original Code
    Session Bean A
    Method 1 --- gets entity Bean B and calls a method on a different object passing this entity bean
              in as a parameter to enable a method on this bean to be called.
    EntityBean lOrderEntity = findOrderEntity(callerUnixLogin, currOrderId);
                   currOrder = lOrderEntity.getOrder();
                   //Logic to update the currOrder object via a method call.
                   persistManager.persistOrder(lOrderEntity, callerUnixLogin, currOrder, psTransactionType);
         persistManager.persistOrder Method:
                   lOrderEntity.setOrder(callerUnixLogin, order);
         findOrderEntity method:
    OrderEntity lOrderEntity = null;
              OrderEntityBeanPK orderPK = new OrderEntityBeanPK(orderId);
              try
                   if (orderEntityHome == null)
                        connectToOrderEntityBean(callerUnixLogin);
                   lOrderEntity = orderEntityHome.findByPrimaryKey(orderPK);
              ... etc
    Current Code
    Session Bean C
    Method 2 ---- calls method 1 in Session Bean A
    Calls to method 2 above happens in quick succession.
    OrderEntityBean class
    ... important methods ...
         private Order order = null;
         public OrderEntityBeanPK ejbFindByPrimaryKey(OrderEntityBeanPK primaryKey)
              throws FinderException, RemoteException, DBOException
              try
                   orderObjectManager.orderIdExists(primaryKey.orderId);
              catch (OMOrderValidationException exc)
                   throw new FinderException(exc.getMessage());
              return primaryKey;
         public void setOrder(String userUnixLogin, Order newOrder)
              throws EJBException, RemoteException, DBOException, OMFormattingException, OMOrderValidationException
              callerUnixLogin = userUnixLogin;
              int version = newOrder.getOrderVersion().intValue();
              if (order.getOrderVersion().intValue() == version)
                   order = null;
                   order = newOrder;
                   Integer newVersion = new Integer(version + 1);
                   order.setOrderVersion(newVersion);
                   newVersion = null;
                   order.setSysUser(callerUnixLogin);
                   orderObjectManager.updateOrder(callerUnixLogin, order);
              else
                   Debug.Print(userUnixLogin, "OrderEntityBean.setOrder: wrong version number for order " + newOrder.getOrdId() +
                        ": expected " + order.getOrderVersion() + " and got " + newOrder.getOrderVersion(), 0);
                   throw new OMOrderValidationException("wrongVersion", order, order.getOrdId(), IName.Order.VERSION, newOrder.getOrderVersion());
         public Order getOrder()
              throws EJBException, RemoteException
    return ((Order)order.clone());
    The following transactions exists for the entity bean ...
    Required:
         create and setOrder methods
    Not Supported
         findByPrimary and getOrder methods

    "The entity bean has a "void setOrder(Order param)" function that writes the Order to a database"
    This functionality should be performed in the ejbStore method().
    "a "Order getOrder()" function that clones and returns the internal Order object."
    Sounds reasonable, except for the cloning part.
    "The "ejbLoad()" function reads the Order object from the database"
    Cool.
    ""ejbStore()" function is not implemented."
    Whoops. Looks like your setOrder method is doing too much. It should do the inverse of getOrder (namely, setting the interal Order object), nothing more. Defer the persistence code to the ejbStore method.
    "According to the SilverStream manual it does not maintain a pool of idle/unused entity beans, instead it instantiates beans as requested."
    Manual? What's that? Assuming that is correct, better hope you don't ever get a high load. You might wanna look into JBoss.
    "2) We sometimes get a TransactionRequired exception thrown when we have concurrent updates to two different objects of the entity bean."
    How can you have concurrent access to two different objects?? Concurrency is inherently applicable to only one object.
    In summary:
    Write your beans properly, ejbLoad populates the bean with data, ejbStore persists the bean's data.
    Get a better (and possibly free) appserver.

  • Entity bean doesn't return hours/min/sec from a Date database field

    Hello:
    I'mm working with Sun One 7 Appserv and Oracle 9i
    I'm having a strange behaviour with getter methods in entity beans when the return value is a Timestamp
    In database, the field's type is Date, but the return value's type is Timestamp
    In this case, the hours/min/sec values return into Timestamp value are always 00:00:00
    For example: in database , F field is a Date and has got the value "12/12/2006 12:30:00"
    After Timestamp t = entityRef.getF() call , t has got the "12/12/2006 00:00:00" value
    The strange case is that in anothers AS ( like JBoss ) , the same code returns right
    Any problem with Oracle 9i in SunOne 7 ? Any problem with JDBC driver ?
    Thanks !
    Best regards

    Well, I found the solution.
    The problem was the ojdbc14.jar driver, which made wrong schema files.
    Exactly, with the bad ojdbc14.jar, generated this entry
    <_type>91</_type>
    when the right for time types is
    <_type>91</_type>
    I dont know beause the new ojdbc14.jar works fine, but I paste its size
    ojdbc14.jar good : 1181679 bytes

  • NotSerializableException on Entity Bean Client

    hi
    Am new to entity beans, specifically Bean-Managed Persistent Entity Beans. I am trying to return a DTO back from the business method of entity bean. In short the code in bean is this
    public EmployeeDetailsDTO getEmployeeDetails(int empNo){
         // Code to fetch emp details
         // Set values in DTO
        return empDetails;
    }On the client side its
    AccountPK pk = new AccountPK("4");
    account = home.findByPrimaryKey(pk);
    EmployeeDetailsDTO empDetails = account.getEmployeeDetails(4);However, i get this excpetion on the cleint.
    java.rmi.MarshalException: error marshalling return; nested exception is: java.io.NotSerializableException:com.tpt.practice.entityBeans.bmp.EmployeeDetailsDTO
    Note: The EmployeeDetailsDTO does implement the Serializable interface. Any other reason why i should get this error?

    Is it possible that a field on the DTO is throwing the Serializable Exception? ..is serialVersionUID manually declared? Perhaps that would help?

  • CMP Entity Bean with ejb-ql finder methods and INFORMIX database

    Hi,
    I have some CMP Entity Beans with finder methods defined in ejb-ql. In my ejb-jar, within <entity> definitions I have something like:
        <entity>
          <abstract-schema-name>BeanName</abstract-schema-name>
          <cmp-field><field-name>fieldOne</field-name></cmp-field>
          <cmp-field><field-name>fieldTwo</field-name></cmp-field>
          <query>
            <query-method>
              <method-name>findAll</method-name>
              <method-params></method-params>
            </query-method>
            <ejb-ql>SELECT OBJECT(o) FROM BeanName o</ejb-ql>
          </query>
        <entity>
    And in persistent.xml:
    <db-properties>
         <data-source-name>datasource_name</data-source-name>
    </db-properties>
    <entity-bean>
         <ejb-name>BeanName</ejb-name>
         <table-name>table_name</table-name>
         <field-map key-type="NoKey">
         <field-name>fieldOne</field-name>
         <column><column-name>column_one</column-name></column>
          </field-map>
         <field-map key-type="NoKey">
         <field-name>fieldTwo</field-name>
         <column><column-name>column_two</column-name></column>
          </field-map>
          <finder-descriptor>
              <method-name>findAll</method-name>
              <method-params/>
         </finder-descriptor>
    Once deployed, on server side, I can found a java source file (with corresponding compiled class file) in path:
    j2ee/cluster/server0/apps/companyName/MyEARApp/EJBContainer/temp/temp38837373733/route/to/package/
    with names:
    BeanName0_0pm.java
    BeanName0_0PM.class
    and the generated java file contains this code:
      public java.util.Enumeration ejbFindAll() throws javax.ejb.FinderException, javax.ejb.EJBException  {
        TransactionContext tc = pm.getTransactionContext();
        Connection conn = null;
        PreparedStatement pSt = null;
        ResultSet ejb_rs = null;
        int status = javax.transaction.xa.XAResource.TMSUCCESS;
        try {
          conn = pm.getConnectionForFindMethod();
          pSt = conn.prepareStatement("SELECT \"O\".\"COLUMN_ONE\",\"O\".\"COLUMN_TWO\", FROM \"TABLE_NAME\" \"O\"");
          ejb_rs = pSt.executeQuery();
    I'm trying to call this method but it throws a SQLException when preparing the statement.
    It seems that Informix does not like this SQL syntax because of upper case names, doble quotes on table alias, or something else.
    When editing persistent.xml in netweaver, I can define the element <datasource-vendor> as ORACLE, SAPDB, MS_SQL_SERVER, DB2_UDB_AS400 or DB2_UDB_OS390 but INFORMIX is not an accepted value.
    Is there any way to define how this SQL query is build?
    Thanks in advance.

    The return type of the finder method defined in the remote home interface is either the entity bean's remote interface or a collection of objects implementing the entity bean's remote interface. The return type of the finder method defined in the local home interface is either the entity bean's local interface or a collection of objects implementing the entity bean's local interface

Maybe you are looking for