Entity Beans and Caching

Hi,
My environment is:
- Weblogic 5.1 running on Solaris
- Oracle 8i database server
- Two physical servers clustered together to form one logical server
I can possibly upgrade to Weblogic 6 or later if it'll help solve my
problem.
Here's what I'm trying to accomplish:
I want to write entity beans using bean-managed persistence. The BMP
part of it is strongly preferred because our DBAs like to see and tune
all of the queries we send from the application.
In many cases, the data I'm querying is largely static. I want to
write EJBs that will cache the data in memory and avoid reading it
from the database server every time the EJB is invoked, unless it
knows that the data has changed.
I've done this successfully with single-server installations, but I'm
not sure how it'll work with a clustered server. Assuming nothing
outside of my two Weblogic servers is updating my database, can I
configure the EJB to have exclusive access to the database and count
on Weblogic to manage the state between the two servers? Or do I have
to implement some kind of custom signalling scheme so that an EJB in
one container can notify any EJBs in the other container with the same
primary key when it has updated the underlying data?
I know from experience that the container will call the ejbStore()
method whenever a transaction ends. My usual BMP pattern in the past
has been to keep track of whether any data has changed during the
transaction and update only those database columns, if any, that
actually changed. But I don't think the store method has any way of
notifying the container as to whether or not it actually stored
anything; hence, I can't see how the container would know when to
order the entity bean on the opposite server to reload itself.
Thanks.

The 6.1 implements functionality you want:
http://e-docs.bea.com/wls/docs61/ejb/EJB_environment.html#1121105
if you use 5.1 you can use this approach:
http://dima.dhs.org/misc/readOnlyUpdates.html
Frank LaRosa <[email protected]> wrote:
Hi,
My environment is:
- Weblogic 5.1 running on Solaris
- Oracle 8i database server
- Two physical servers clustered together to form one logical server
I can possibly upgrade to Weblogic 6 or later if it'll help solve my
problem.
Here's what I'm trying to accomplish:
I want to write entity beans using bean-managed persistence. The BMP
part of it is strongly preferred because our DBAs like to see and tune
all of the queries we send from the application.
In many cases, the data I'm querying is largely static. I want to
write EJBs that will cache the data in memory and avoid reading it
from the database server every time the EJB is invoked, unless it
knows that the data has changed.
I've done this successfully with single-server installations, but I'm
not sure how it'll work with a clustered server. Assuming nothing
outside of my two Weblogic servers is updating my database, can I
configure the EJB to have exclusive access to the database and count
on Weblogic to manage the state between the two servers? Or do I have
to implement some kind of custom signalling scheme so that an EJB in
one container can notify any EJBs in the other container with the same
primary key when it has updated the underlying data?
I know from experience that the container will call the ejbStore()
method whenever a transaction ends. My usual BMP pattern in the past
has been to keep track of whether any data has changed during the
transaction and update only those database columns, if any, that
actually changed. But I don't think the store method has any way of
notifying the container as to whether or not it actually stored
anything; hence, I can't see how the container would know when to
order the entity bean on the opposite server to reload itself.
Thanks.--
Dimitri

Similar Messages

  • Are EJB ( entity beans) are cached ?

    Are EJB ( entity beans) are cached ?
    I have a doubt here . As per my understanding , the entity beans are cached from the database. In that case , If I delete a row in the database by an external application ( say using TOAD tool) , how the Entity bean will be updated / reloaded ? Entity bean will be out of sync then .
    Application server : weblogic/webspehere .

    >
    You can use the refresh method of the EntityManager interface to read new values from the database (if you expect it to be out of sync), and use locks to prevent others from changing your data while the application is performing actions in a transaction.Did you mean I have to write code for this ? can't be made it automatic refresh by the container ? Is there any settings I can configure so that container can do it by itself proactively ?
    Also, using locks ...is this a container settings or I need to configure myself in ejb-jar.xml ? Could you please shed some light here ?

  • How to use same transaction when calling CMP entity beans and  DAO (JDBC)

    We are currently using Weblogic 8.1 SP2 with an Oracle 10g database (using XA thin and non-XA drivers).
    We have a session bean that invokes an entity bean and a DAO (data access object pattern) in order to add data in 2 separate tables (account and history). Rows are added to the first (account) table using a CMP Entity bean while inserts are done in the 2nd (history) table using a DAO. Here is some pseudo code:
    addHistorySessionBean (trans-attribute="Required")
    begin
    Step #1 - call addAccountEntityBean (trans- attribute="Required")
    Step #2 - call addHistoryDAO (get datasource, connection)
    end
    The 2nd table (history) has a foreign key constraint to ensure that the corresponding key exists in the first (account) table. Unfortunately, DAO inserts on the 2nd (history) table fail with a foreign key constraint violation (INTEGRITY CONSTRAINT VIOLATION - PARENT KEY NOT FOUND!) since they cannot see the row added to the 1st (account) table in step #1 by the CMP entity bean.
    How does one ensure that all this is done in a single transaction ? It appears that the app server creates two seperate transactions (one for the session bean facade and the entity bean and a 2nd transaction (when we retrieve a connection using the same data source JNDI name) for the DAO.
    A post on server side suggested using a "<resource-ref>" in the session bean to tie the two potentially separate transactions together, but that does not work for us. However, I am not sure if we are doing that correctly. After we define the resource ref in the session facade bean, do we use the resource ref "name" attribute to lookup the datasource or do we still lookup the datasource by JNDI name ? Do we need to define the resource-ref tag in the entity bean also ?
    Does Weblogic allow using a single transaction for this type of a scenario ? How does one specify within Weblogic that the same transaction should be utilized by the entity bean and any subsequent DAOs?
    People have also suggested that we defer constraint checking until the transaction(s) are committed but that sounds like a work acount without addressing this issue. Would postponing the constraint checking in Oracle cause any additional overhead ?
    Any suggestions with specific examples or documentation on how to address this issue will be gratefully appreciated.

    Thanks for your suggestion. Unfortunately, this does not work since it appears that there are 2 separate transactions going on here. One, the original one initiated by the session bean and used by the entity bean and the other initiated by the DAO. Any other ideas appreciated.
    Hi,
    Try setting the delay-database-inserts tag to
    ejbCreate in RDBMS descriptor file.
    http://bernal/stage/wls/docs81/ejb/DDreference-cmp-jar
    .html#1113981
    vasanthi ramesh

  • 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

  • Entity beans and data synchronization

    I want to use a BMP to represent information about a database entity where the BMP "fields" are actually statistical summaries (e.g., an Account bean where the "field" num_transactions is calculated using a query rather than stored). I want to do this because the queries that generate the summary statistics are costly and I want to cache the results in memory. Since these are "read-only" statistics, I could use DAOs and a Fast Track Reader but I want to make use of the caching and lookup facilities of J2EE for finding accounts that are already cached.
    I only refresh the back end database nightly, so I need to flush all of the values in all cached Account beans nightly. Is there a facility for this type of thing, or do I need to manually control it (e.g., using a "version" number on the data that is checked periodically).
    Thx,
    John H.

    John,
    You might also check your application server's documentation. Weblogic provides a read-only entity bean, whereby you can specify a timeout parameter in your descriptor file. The container will then only call ejbLoad() when the ejb is accessed and the timeout has been passed. This, in effect, provides a caching mechanism.
    Best of luck,
    Richard

  • EJB 3.0 entity beans and WebDynpro models

    Hi all,
    first off all my setup:
    WebDynpro Development Component: dcA
    EJB Module Development Component: dcB
    i wan't to create Entity Beans in dcB an use it for my model in dcA.
    My questions:
    1. Why does the "New Wizard" only offer EJB 3.0 Session and Message Beans an no Entity Beans? What is the correct way for creating Entity Beans in DevStudio?
    2. Is ist right that i have to define a public Part containing the Entity Bean to make it visible to dcA?
    Regards,
       Christian

    Hi,
    I'm experiencing same problems, is this a bug or an feature?

  • Read Only entity beans and Finders

    Hi,
    We are using Read Only entity beans with WLS 7.0 SP1 for some entities that represent Reference Data that will never change. What I would like to know is whether WLS needs to hit the database when a finder on these beans is run or does WLS cache the results of the Finder also?
    Thanks.
    Santosh

    Hi,
    we use read only entity beans. It is beneficial if have findByPrimaryKey finders. but we also have finders on non primary key coloumn also. is there a way to cache such local references returned by such non primary key finders also.

  • EJB entity beans and BC4J

    I have looked at BC4J and it looks good. Buy my question is that isn't this frame work in direct conflict with EJB entity beans. I know lot of stuff that is there in BC4J should have been in EJB enitiy beans, but as a developer why should I go with BC4J and not the standard EJB stuff considering the fact that BC4J is properietery to Oracle?Any thoughts?

    Vimal,
    Without going into exhaustive detail here, I would like to recommend that you take a look at the BC4J Technical White Paper available from the JDeveloper page on OTN (in the 3.0 Technical Information section):
    http://technet.oracle.com/products/jdev/info/techwp20/wp.html
    Amoung other things to note, BC4J is based on pure Java, and is what we consider a 'white box', meaning, you as a developer have complete control over what is going on. You can extend any of the code generated to customize it.
    Primarily though, the major benefit of BC4J is that we have taken care of most of the complicated communication code for you. Communication between the client and the data server, transaction handling, row locking, etc are already written for you. You just use, extend, customize what we have provided.
    In addition, BC4J allows you flexibility in your deployment environment decision. Regardless of where and how you deploy your BC4J Application Module, the client is unchanged.
    Those are the key advantages. Again, for more details, I would take a look at the white paper to see if it more fully addresses your questions.

  • Container Managed Entity Beans and Client Identifier in Oracle

    Is it possible to use Container Managed Entity Beans (EJB with CMP)
    in a way that the Oracle database sessions still know the
    individual Client Identifiers of the actual users
    (not just the Identifier of the proxy user defined in the
    Connection Pool)?
    If Yes: How?
    If No: The consequence would be that the
    technologies EJB with CMP cannot be user together with
    Oracle Virtual Private Databases (VPN) because VPN requires
    some kind of Client Identifier.
    I am grateful for any hint.
    Regards,
    Martin Siepmann
    +49 (0)163 / 7765328

    Not quite an auto-incrementing PK, but it is managed by the container. the following is from the turorial
    Generating Primary Key Values
    For some entity beans, the value of a primary key has a meaning for the business entity. For example, in an entity bean that represents a phone call to a support center, the primary key might include a time stamp that indicates when the call was received. But for other beans, the key's value is arbitrary--provided that it's unique. With container-managed persistence, these key values can be generated automatically by the EJB container. To take advantage of this feature, an entity bean must meet these requirements:
    * In the deployment descriptor, the primary key class is defined as a java.lang.Object. The primary key field is not specified.
    * In the home interface, the argument of the findByPrimaryKey method must be a java.lang.Object.
    * In the entity bean class, the return type of the ejbCreate method must be a java.lang.Object.
    In these entity beans, the primary key values are in an internal field that only the EJB container can access. You cannot associate the primary key with a persistent field or any other instance variable. However, you can fetch the bean's primary key by invoking the getPrimaryKey method, and you can locate the bean by invoking its findByPrimaryKey method.
    Maybe that is good enough
    christina

  • Strange behavior with entity beans and servlets in a cluster

    We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
              Packs installed. When a client uses the deployed entity beans or
              servlets they work every other time. The times they do not work nothing
              happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
              nothing. I suspect something in the cluster setup since we do not have
              these same problems on non-clustered entity beans or servlets. We have
              made sure all the entity beans have the Shared Database flag set on and
              added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
              That didn't fix the problem. Any ideas?
              Thanks in advance,
              Dallas Dempsey
              DEM - Houston, TX
              

    Do you have log files?
              - Prasad
              Chris Dempsey wrote:
              > We have 2 WebLogic 4.5.1 servers in a cluster with none of the Service
              > Packs installed. When a client uses the deployed entity beans or
              > servlets they work every other time. The times they do not work nothing
              > happens. No exceptions, no responses to the client ( i.e. HTTP 404s ),
              > nothing. I suspect something in the cluster setup since we do not have
              > these same problems on non-clustered entity beans or servlets. We have
              > made sure all the entity beans have the Shared Database flag set on and
              > added the delayUpdatesUntilEndOfTx false to the enviroment of the DD.
              > That didn't fix the problem. Any ideas?
              >
              > Thanks in advance,
              > Dallas Dempsey
              > DEM - Houston, TX
              

  • Use same transaction in entity-bean and Datasource

    Hello
    I've got following problem. In my stateless container managed transaction Sessionbean i do some inserts and update on my container managed entity bean. In the same transaction I have to read some informations on the database. Some of those informations are already set by the entity bean, but not yet commited. Now I want to read them through a javax.sql.DataSource. But this Datasource doesn't use the same transaction as the session bean.
    Question: Is it possible to let a Datasoucre use the same Transaction as Sessionbean?
    (i work with WSAD 4.0.3)
    Thanks

    Hi,
    You would have to check that you are using an XADataSource instance, instead of a 'regular' DataSource instance (which will not adopt the transaction started by the application server). In particular, the JNDI lookup name of the DataSource should actually point to an instance of XADataSource; a special type for container transactions.
    The administration/deployment tools of the WS will allow you to do that, under Resource Factories or DataSources somewhere.
    Both types look the same towards your application code, so your session bean is probably fine the way it is and does not need rewriting. It is merely in the setup of the WS server that the difference lies.
    Best,
    Guy
    http://www.atomikos.com

  • Cmp Entity Beans and collections

    I am doing a proof of concept application and I have implemented an Entity bean which accesses through a DAO object to my Informix database and returns records based on a serial field called sightID. This works fine and I can access the records and store new records. I now need to demonstrate the power of CMP beans and return a collection showing all records for a particular field called Type. Here is where my problems start. If I am using CMP I need to map the primary key field to the primary key field of the database (this is sightID) the field I need to get the collection on is not a key field and is only a text field with one of four values. How can I use CMP to return a collection based on a non priomary key field? is this possible? I am willing to post all my code but there is 14 pages.
    any help greatly appreciated
    Connie

    EJBQL???..
    SELECT object(o) from table_object 0 where non_primarykey = 'value i want'
    sanjay.

  • CMP Entity Beans and multiple tables

    Hi All,
    Is it possible to have a CMP Entity Bean retrieve attributes from multiple tables
    (using table join), and populate attributes from columns in both tables?
    If yes, how do we configure the same in configuration xml files.
    Is there any special handling required for this in the bean itself?
    Thanks,
    Prabh

    Hi All,
    Is it possible to have a CMP Entity Bean retrieve attributes from multiple tables
    (using table join), and populate attributes from columns in both tables?
    If yes, how do we configure the same in configuration xml files.
    Is there any special handling required for this in the bean itself?
    Thanks,
    Prabh

  • Problem with cache refresh entity bean / server node

    Hello,
    ive got a big problem and not found answer in sdn until now.
    Ive got a job that gets data from maxdb by sapjob - jco - session bean - entity bean - database.
    this job works daily. the data to work with is written directly to database from external.
    on first execute it works, but second etc not. i search for answer and i guess something:
    entity bean is cached (increase percormance?) with results of the select and do not know about new database entries when they are written directly to database. so second select says: there is no new data (but they are there).
    i only get this new data when i restart netweaver server node, then it works, but only for one time. then result is in cache and then i have to do same procedure before it goes (restart server).
    how can i get this data? is there any setting for force node to refresh cache? or any other settings to affect something like this?
    we have to go live with this in august.
    thx for help.
    Version: NW04, SP21

    thanks at first.
    OSS was the next step i consider, enforcedly.
    I hoped that there was a kind of timeout in visual admin or somewhere else where (for example) i can set a special time (seconds?) for refreshig the cache. Or i can set a flag for "do not cache entity beans".
    Someone else any idea?
    Nowadays on test system whe have made a task that starts windows every night so that netweaver also is "fresh". a kind of resolution but not the best and no resolution for the productiv system. or whe have to write a kind of batch job that only restarts server node once a day.
    New Info:
    I think cache was filled directly after restart.
    when we restart, then data are written, and then our application wanted to read them, they are also not seen.
    The data are only seen by bean when the restart takes place AFTER the data are written into db.
    So we change restart time to point after data are written. so we will test if this works, on monday we will see.
    Edited by: Torsten on Jul 11, 2008 11:27 AM

  • Entity Bean Rollback fails: caches are out of synch with the database

    We are encountering a critical issue where the rollback of a session transaction rolls back any database changes, but doesn't roll back bean changes in memory. When we next access the bean, it returns information that should have been rolled back. The memory cache is out of synch with the database.
    We have a simple session bean S, using container managed transactions. We also have an entity bean E using bean managed persistence. E has a single member <name>.
    We implement a method s() in S with <trans-attribute> Required as follows:
    public void s() {
    Context lookupContext = getLookupContext();
    SHome shome = (SHome) lookupContext.lookup(SHome.NAME);
    S s = shome.findByPrimaryKey(thePrimaryKey);
    System.out.println("-- current name = " + s.getName());
    s.setName("IGNORE");
    EJBContext ejbContext = (EJBContext) getContext();
    ejbContext.setRollbackOnly();
    Since this is BMP, the setName call issues our SQL update against the S record. When the session transaction rolls back, the database changes are also rolled back. But the entity bean in memory shows the modified name. We can see this in the next call to s() since the getName() returns IGNORE rather than the original value. We have also gotten debugged into the underlying instance cache associated with the S bean descriptor. I.e.
    AbstractEJBHome ejbHome = (AbstractEJBHome) lookupContext.lookup(SHome.NAME);
    AlternateHashTable aht = ejbHome.getBeanDescriptor().getCache();
    Looking at this map of bean instances also shows that the bean instance for S is not rolled back.
    From previous conversations with the server technologies team, we understand that during the transaction, we should be working on a cloned copy of the S bean. Upon rollback, the copies should be discarded rather than merged back to the cached bean. They seem to be merged regardless of rollback state.
    We are using OC4J 10.1.3.0.0 (build 060119.1546.05277).

    Actually, what one or the developers in my group found out is two things:
    1) The clone is a shallow copy.They copy the references but not objects themselves. This has been causing problems for us.
    2) It seems that you don't work on a copy and you work on the original and they keep a copy. Now, this is fine IF you don't have multiple threads working on the same Entity bean and we moved our application from Weblogic where it throws an exception if that Entity bean is in use to OC4J which is suppose to copy the bean and doesn't so you have multiple threads possibly modifying the same object.

Maybe you are looking for

  • What are my options for using my Verizon iPhone 6 in Europe next summer?

    I just bought an iPhone 6 through Verizon.  Will I be able to use it during my trip to Europe next summer?  Is there website somewhere that tells me what I need to do? The Verizon website seems totally unhelpful on this subject, and so far I'm not ha

  • Error when starting FireFTP

    Error message= TypeError: document.getElementsByTagName(...)[0] is undefined URL= chrome://tidynetwork/content/overlay.js Line Number= 14

  • Passing Parameters between Java Portlets

    i hava java portlet and it does a search... the search result appears within the portlet region.... but i want to be able to click on the search button and take it to another portal page and have a portlet that contains the result of the porltet... h

  • Viewing photo problems

    I have had my iPhone 5s around 2 months and this week have noticed if I take a photo it appears in the box on bottom left corner on the camera screen but when I go to my photos there are not there so can't use them for anything. Anyone know what this

  • E72 "System Error" message when turning on WLAN sc...

    Ever since I've upgraded my E72 to version 51, phone tends to crash almost every time I turn on WLAN scanning, displaying a System Error message, forcing me to lose all my data, including applications I've paid for. Upgrading to version 53 did not fi