Caching in TopLink

Hi,
I have created a session bean in a TopLink Project. This hits a DB.
My proc is as follows:
public Vector findHR()
Session session = getSessionFactory().acquireSession();
String sqlStatement="select * from locations where location_id > 1100";
DataReadQuery readQuery = new DataReadQuery(sqlStatement);
//readQuery.dontMaintainCache();
Vector queryResults = (Vector)session.executeQuery(readQuery);
if(queryResults != null)
System.out.println("Size=" +queryResults.size());
session.release();
return queryResults;
I have created a datacontrol out of this proc and have put the same on a form.
Now my Qs are:
1)when I fire the 'dynamic' query "select * from locations where location_id > 1100" then does TopLink generate an Object when it returns the results?
2) On successive invocations, does it cache the object and avoid DB hits?
3) Is the call to dontMaintainCache() valid in here?? - this is to avoid caching and making the query hit the DB again and afresh.
Regards,
venkat

This is a followup to Venkat's question...
We need a mechanism to execute queries. These queries will be stored in the table and these queries can change. We don't want to create / modify the entity bean when there is a addition or modification in the sql queries. Also these SQL queries are complex and the business logic is stored in plsql functions / procs. We can't create java objects as we don't have a visibility on the data structures that will be required to accommodate the data that can be returned by those queries.
questions we have is
is it a good design to have such dynamic queries - we seem to loose the TopLink cache. Is there any other big disadvantage in doing that? Any thoughts if its not advisable?
Is there any other known mechanism to achieve such functionality?
We are using oc4j as an application server and can use EJB 3.0 as another option - but couldn't find a way to write such dynamic query without creating the java classes.
Thanks in advance!
Regards,
-Pranav.
Message was edited by:
user533287

Similar Messages

  • How can we maintain External cache in TopLink JPA

    Hi,
    JPA maintains shared session cache for the purpose of multiple users .Individual user can not use this shared session cache . How can we maintain that individual user cache in TopLink JPA . In our application we are using container managed transactions.
    Regards
    Sucharitha.

    I'm not sure I understand, perhaps you could clarify your question?
    Do you want to access an object from the shared cache? There is a TopLink JPA query hint "return-shared" to allow for read-only shared objects to be returned on a query.
    If you do not wish to have a shared cache, you can set the cache to be isolated (see @Cache annotation, or persistence property "eclipselink.cache.shared.<class>").
    You can also access the shared cache directly using getServerSession().getIdentityMapAccessor().

  • Hibernate's dual-layer cach and TopLink's caching strategy

    Dear members,
    I understand that caching between hibernate and toplink is implemented (or utilized) differently. Hibernate seems to have 'dual-layer caching' (which may imply they have two layers of cache) whereas TopLink has session cache and shared cache. The way I see it, they seem to be aiming for the same thing. Are there any differences between (obviously there are, only that I do not know them) those two caching architectures, and how different are they?
    Howard

    Yes there are differences :) For details check out
    TopLink vs Hibernate... revisited... again :)
    and
    Indirection - how are references resolved after session has been closed?

  • Sequence caching with toplink and oracle caching

    Hi,
    In my application, I use toplink as a JPA provider. For performance reasons, I defined an allocationSize on sequence generator for some persistence objects. I read some documentation to understand how it works, the result of my research is that the allocationSize of sequence generator must match with the increment value of the sequence in database.
    So if I want to cache 1000 of values, I must define on my sequence generator allocationSize of 1000 and create a sequence like this : create sequence myseq increment by 1000. Am I right ?
    Second question, what if my sequence define a cache in the database. For example, create sequence myseq increment by 1000 cache 20.
    Does it mean that 20 values will be cached or 1000*20 values will be cached ? Is the cache size defined per session or for all the sessions of the database ?
    Thanks.
    Will.

    Thank you for your response.
    I used the default parameter of toplink (increment by 50) and I left a cache size of 20 on database side.
    But I noticed that whenever the server restarts, I "lost" between 900 and 1000 ids (nearly 20*50). So even if sequence cache on oracle size is non transactional, I think there is a kind of prefetch somewhere on the server side. I must not lost more than 50 ids when a server restarts.
    If I remove the cache on database side, then the behavior is correct (the expected one to be more precise).
    Is there any kind of sequence caching in oracle jdbc drivers ?
    Thanks.
    Will.

  • How to refresh cache in TopLink, turn off cache

    How does one refresh TopLink's cache resulting from an event change? As an example, if a stored procedure is triggered by a process independent of TopLink, how do I tell TopLink to refresh its cache.
    Also, how does one turn off TopLink cache altogether. Thanks.

    I do not typically recommend turning the TopLink cache off all together. The cache is also key for managing object identity. If you have data that changes outside of your Java applications knowledge then there are several strategies to handling the stale data situation in the cache.
    1. Make sure you setup a locking strategy so that you can prevent or at least identify when values have already changed on an object you are modifying. Typically this is done using optimistic locking. There are several options (numeric version field, timestamp version field, some or all fields). Full details available in the docs.
    2. Configure that cache appropriately per class. If the data is being modified by other applications then use a weaker style of cache for the class. SoftCacheWeakIdentityMap or WeakIdentityMap will minimize how long de-referenced objects are held in the cache.
    3. Force a refresh if needed. On any query a flag can be set to force the query's execution to refresh the cache. (http://otn.oracle.com/docs/products/ias/doc_library/90200doc_otn/toplink.903/tl_flapi/oracle/toplink/queryframework/ObjectLevelReadQuery.html#refreshIdentityMapResult())
    4. If the application is primarily read based and the changes are all being performed by the same Java application operating in a cluster you may want to look at TopLink's cache-sync feature. Although this won't prevent stale data it should greatly minimize it.
    5. One less frequently used option is to build infrastructure that can notify TopLink's cache when something changes on the database. This involves building your own call-out mechanism from a trigger into the Java application hosting the TopLink session and cache. In the Java space you can make use of the cache API to force refresh, update the object yourself, or mark it as dirty. I would discourage removing it from the cache at the object may still be in use.
    I hope this explains stale-data management at a high level. More details can be found throughout the TopLink documentation.
    Doug Clarke
    Product Manager
    Oracle9iAS TopLink

  • Is "Process scoped identity" the same thing as TopLink shared cache?

    Bumped into this thread on my investigation of ORM solutions:
    http://forum.hibernate.org/viewtopic.php?t=939623&highlight=toplink
    What I would like to know is whether "Process scoped identity" as Gavin King puts it, is the same as TopLink shared cache and if so, whether this could cause deadlocks?
    Quote:
        All the docs for Hibernate assume that you are working in a multi-user system,
        where process scoped identity is an absolute no-no - you would require
        synchronization on entity instances, which is guaranteed to result in deadlocks,
        since there is no possible "natural" order in which to obtain locks.

    Yes, process scoped identity is basically what TopLink's shared server session cache is offering. Having shared instances is a huge benefit for performance and is most noticeable with read-only and read-mostly data types shared across users.
    Yes, we do need to have locking to ensure that changes are safely written into the shared instance and that transactionally isolated (UnitOfWork) copies are safely made in a row consistent fashion. Although I cannot comment on Hibernate's implementation I assume that whatever object type they use in their shared (L2) cache offers the same concurrency protection to ensure that users get consistent data and that concurrent writes do not corrupt the cached object structure.
    I guess the only real difference is the object type cached. TopLink cached your business object and Hibernate caches a custom object representing the state of you object. Both need to ensure proper locking for concurrency protection but TopLink does not need to rebuild an instance for each client session unless wanted/needed.
    Doug

  • Refresh toplink cache from tirgger

    How to update the toplink cache due to change in the database by some external process or procedure?
    This question was posted some time back and one of the suggestion was to create a trigger on the table holding the data and implement callout to the toplink cache to refresh. I will appreciate if any one can let me know where I can I find more information to implement such a callout method from trigger on the database table.
    We are accessing the toplink objects from OC4J container from where a singleton is managing the calls to the toplink objects. We already have methods in place to refresh the cached object based on timeouts but now the new requirements are to refresh the objects only if the data is changed in the database.
    Thanks
    Ahmad

    I have url error on this thread : How to refresh cache in TopLink, turn off cache
    [b]Discussion Forums Error
    We cannot process your request at this time. Please try again later.
    Thank's

  • [JPA] Invalidate TopLink Essentials' L2 cache. How?

    Hi,
    I'm trying to invalidate the L2 cache of TopLink Essentials. In Java SE, I try something like this:
         Customer cust = em.find(Customer.class, 1L);
         System.out.println(cust);
         em.clear();
         em.close();
         em = emf.createEntityManager();
         Session session = ((EntityManagerImpl)em).getSession();
         session.getIdentityMapAccessor().invalidateAll();
         cust = em.find(Customer.class, 1L);
         System.out.println(cust);The trouble is that only ONE SQL statement is generated, not two, as I would have expected.
    In Oracle Application Server, I cannot even get this far because I cannot cast to EntityManagerImpl. There, the class hierarchy is:
         com.evermind.server.ejb.persistence.EntityManagerProxy
                implements com.evermind.server.ejb.persistence.ContainerEntityManager
         com.evermind.server.ejb.persistence.AbstractEntityManagerProxy
                implements javax.persistence.EntityManager
         java.lang.ObjectSo, how can I do this in Java SE and in a container?
    Best regards,
    Bisser

    Hello Bisser,
    getSession() only returns the active session (the underlying UnitOfWork) if one is available or null if not. Use getServerSession() instead.
    As for in the container, you need to call getDelegate() to get the wrapped entitymanager.
    Best Regards,
    Chris

  • TopLink Essentials: Using spring session scope on the EntityManagerFactory

    Hi,
    In one of our projects we are trying to utilize the 2nd level cache of TopLink Essentials. The server code is using the Spring (2.0.7) and is deployed to a web container. We are using a Java client and serializes every object between the client and the server.
    When a client is started a lot of "static/common" data is read from the server. The first client started will therefor pay some extra performance cost, but additional clients should hopefully be able to perform better due to the cache. Most of the static data is accessed not using JPQL and should therefor not bypass the cache.
    If we configure the EntityManagerFactory using default Spring scoping (singleton) it seems like we are not able to utilize the cache. We can see from the log files that each time a client is started a lot of SQL is executed towards the database (Oracle).
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
            <property name="showSql" value="false" />
            <property name="generateDdl" value="$repository{toplink.generateDdl}" />
            <property name="database" value="$repository{toplink.database}" />
          </bean>
        </property>
        <property name="jpaProperties">
          <props>
            <prop key="toplink.weaving">static</prop>
            <prop key="toplink.logging.level">FINEST</prop>
          </props>
        </property>
      </bean>When we changes the scoping to spring session the behavior is very different. Then we can see that the first client generates a lot of SQL towards the database and pays a startup cost, while subsequently clients seems to be able to utilize the cache.
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" scope="session">
        <aop:scoped-proxy />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
            <property name="showSql" value="false" />
            <property name="generateDdl" value="$repository{toplink.generateDdl}" />
            <property name="database" value="$repository{toplink.database}" />
          </bean>
        </property>
        <property name="jpaProperties">
          <props>
            <prop key="toplink.weaving">static</prop>
            <prop key="toplink.logging.level">FINEST</prop>
          </props>
        </property>
      </bean>Having read the documentation of the spring session scope I'm having a hard time explaining this behavior. As I understand it the EntityManagerFactory will be stored in the HTTP session resulting in a new EntityManagerFactory for each session. I cannot understand how this may result in that we are able to utilize the 2nd level cache? What are the relationship between the EntityManagerFactory and the 2nd level cache?
    Is this an accepted way of configuring the EntityManagerFactory or will there be a downside?
    I hope someone are able to explain this behavior for me:-)
    Best regards,
    Rune

    Hi Rune,
    To understand the shared cache behavior you actually need to understand more about what TopLink Essentials does than what Spring does. When a new factory is created, TopLink Essentials actually just proxies the server session with a factory instance, so the same server session is used. This is why you are seeing the same cache used across multiple factories of the same session.
    In the first case, if you are not using JPQL then what are you using to load the data and why are you thinking that it will not bypass the cache?
    Using a factory instance for each session is not what I would recommend doing as there are some additional costs associated with establishing a factory (even though the session already exists). The first way should be the correct way, I am just not sure what the circumstances are that are causing your cache to not be warmed. You may want to post more details about that so people can better help you out with that angle.
    -Mike

  • JPA -- Don't Maintain Cache

    Hi,
    Is it possible to specify for a NamedQuery (or NamedNativeQuery) that I don't want its results to go into the cache? Something like TopLink's:
    <toplink:maintain-cache>false</toplink:maintain-cache>I have some queries which really don't need to store their results in the cache. I tried with:
    q.setHint(TopLinkQueryHints.REFRESH, HintValues.FALSE);But the results still seem to go into the cache. So, apparently TopLink Essentials puts them in the cache the first time, but simply doesn't refresh them after the subsequent database fetches.

    Thank you, James!
    The trouble is that the cast to DatabaseQuery kills the portability. If I start doing such things, there won't be any point in switching to JPA. We could just go on using TopLink.
    As for the property:
    <property name="toplink.cache.type.[[[ENTITY]]]" value="NONE"/>the trouble is that it will turn off the caching for the entire entity. Instead, I just want to turn off the cache for certain batch queries.
    I had a very similar problem with calling Stored Procedures from JPA. I was forced to do things like:
    Query q = em.createNamedQuery("some_dummy_query");
    EJBQuery eq = (EJBQuery)q;
    ValueReadQuery vrq = new ValueReadQuery();
    SQLCall c = new SQLCall("begin ####res := pkg.func(#inp); end;");
    vrq.setCall(c);
    eq.setDatabaseQuery(vrq);
    q.setParameter("res", Long.valueOf(1));
    q.setParameter("inp", Long.valueOf(2));
    Object o = q.getSingleResult();
    System.out.println(o + "    (" + o.getClass().getName() + ")");Very ugly stuff. Also, custom mappings are not available. For example, it's a pain to map an enum to a legacy database.
    I'm beginning to think that we should wait for JPA v2 before we do the switch.
    Thank you for your assistance.
    Best regards,
    Bisser

  • Toplink in a cluster architecture

    Hi,
    I'm trying to integrate TopLink in a clustered application server architecture (EJB + Servlet) with dynamic memory sharing for HTTP session synchronisation using Datasources for access to the DB.
    The DB should also be clustered (this is not sure and will be decided at a later point but should not have any bearing on the configuration of TopLink).
    I have only found some very vague information about clustering the cache of TopLink.
    Can anyone give me more information about how it works, how to parameter it and the does and don'ts?
    Thank you

    TopLink's cache-sync using JMS is documented at:
    http://download-east.oracle.com/docs/cd/A97688_12/toplink.903/b10064/enterpri.htm#1022229
    This shows examples of using sessions.xml and Java API to configure the use of JMS. You will need to configure your JMS to operate in your application server cluster. This will involve you following the instructions of your JMS to create a connection factory and topic that TopLink can make use of.
    One note of caution about using cache-sync in general though. It does not eliminate concurrency issues and it does not prevent stale data. It minimizes the chance of stale data and is typically most efficient in systems with a small percentage of writes compared to read operations.
    You will need to build your application taking concurrency into effect. This will involve setting up locking (typically optimistic locking) on all concurrently accessed types and also ensuring that the commit of UnitOfWork will catch all locking failure exceptions and handle them correctly.
    If you are building a system with a larger (&gt; 15%) percentage of writes you will probably not want to use cache-sync and may be more interested in proper cache configuration (use WeakIdentityMap for volatile data) and using possibly using refresh on queries in critical sections of the application's code. You will still require locking for these configurations as well.
    Doug

  • Corrupt Object message after cache validation

    Help!
    I am trying to delete a single UserEvent object that is in a one to many collection private owned by a User object.
    The way I am doing this is by
    1) building a prototype of the UserEvent to delete,
    2) setting its primary key attributes (User and date),
    3) reading the actual cache object,
    4) registering the actual cached object in the unit of work and obtaining a working copy,
    5) removing the UserEvent working copy from the its User's UserEvent collection, and
    6) setting the User reference in the UserEvent working copy to null
    When I commit the unit of work I do not see any delete statements. Instead I called printRegisteredObjects();
    validateCache();
    validateObjectSpace();
    and in my output I see a "cache corrupt" message. I have searched the forums for this and found nothing - can someone kindly give me a clue about how to debug this?
    Many thanks
    James Carlyle
    eventPrototype.setUser(user);
    eventPrototype.setEventDate(new Date(Long.parseLong(eventTimes[s])));
    UserEvent actual = (UserEvent) getReadSession().readObject(eventPrototype);
    UserEvent workingCopy = (UserEvent) this.getUnitOfWork().registerExistingObject(actual);
    System.out.println(workingCopy.getUser().getUserEvents().remove(workingCopy));
    workingCopy.setUser(null);
    workingCopy.setEventSource(null);
    workingCopy.setEventType(null);
    this.getUnitOfWork().printRegisteredObjects();
    this.getUnitOfWork().validateCache();
    this.getUnitOfWork().validateObjectSpace();
    <opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
    <opm:attribute-name>userEvents</opm:attribute-name>
    <opm:reference-class>com.sky.skynet.core.UserEvent</opm:reference-class>
    <opm:private-owned>true</opm:private-owned>
    <opm:target-foreign-key>
    <opm:field-reference>
    <opm:source-field table="USEREVENTS" name="USERID" xsi:type="opm:column"/>
    <opm:target-field table="USERS" name="USERID" xsi:type="opm:column"/>
    </opm:field-reference>
    </opm:target-foreign-key>
    <toplink:container xsi:type="toplink:list-container-policy">
    <toplink:collection-type>oracle.toplink.indirection.IndirectList</toplink:collection-type>
    </toplink:container>
    <toplink:indirection xsi:type="toplink:transparent-collection-indirection-policy"/>
    <toplink:selection-query xsi:type="toplink:read-all-query">
    <toplink:container xsi:type="toplink:list-container-policy">
    <toplink:collection-type>oracle.toplink.indirection.IndirectList</toplink:collection-type>
    </toplink:container>
    </toplink:selection-query>
    </opm:attribute-mapping>
    [TopLink Finest]: 2005.02.10 12:09:49.966--ServerSession(1527262533)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Execute query ReadObjectQuery(com.sky.skynet.core.User)
    [TopLink Finer]: 2005.02.10 12:09:54.640--ServerSession(1527262533)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--client acquired
    [TopLink Finest]: 2005.02.10 12:09:54.641--ClientSession(1493049610)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Execute query ReadObjectQuery(com.sky.skynet.core.UserEvent)
    [TopLink Finer]: 2005.02.10 12:09:54.642--ServerSession(1527262533)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--client acquired
    [TopLink Finer]: 2005.02.10 12:09:54.663--ClientSession(1736789279)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--acquire unit of work: 1638538680[TopLink Finest]: 2005.02.10 12:09:54.664--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Register the existing object com.sky.skynet.core.UserEvent@608a6351
    [TopLink Finest]: 2005.02.10 12:09:54.676--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Register the existing object com.sky.skynet.core.EventSource@69eb424b
    [TopLink Finest]: 2005.02.10 12:09:54.677--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Register the existing object com.sky.skynet.core.EventType@544d8040
    [TopLink Finest]: 2005.02.10 12:09:54.677--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Register the existing object com.sky.skynet.core.User@2c1f14fd
    [TopLink Finest]: 2005.02.10 12:09:54.687--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Register the existing object com.sky.skynet.core.UserEvent@608a6351
    05/02/10 00:09:54 true
    [TopLink Severe]: 2005.02.10 12:09:54.696--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--
    UnitOfWork identity hashcode: 1638538680
    All Registered Clones:
    Key: [1] Identity Hash Code: 1252288055 Object: com.sky.skynet.core.EventType@4aa46637
    Key: [1] Identity Hash Code: 1968164628 Object: com.sky.skynet.core.EventSource@754fcf14
    Key: [Fri Mar 20 05:00:00 GMT 2020 null] Identity Hash Code: 748356780 Object: com.sky.skynet.core.UserEvent@2c9b04ac
    Key: [801] Identity Hash Code: 1865599785 Object: com.sky.skynet.core.User@6f32cb29
    [TopLink Finer]: 2005.02.10 12:09:54.696--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--validate cache.
    [TopLink Finest]: 2005.02.10 12:09:54.699--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--stack of visited objects that refer to the corrupt object: []
    [TopLink Finer]: 2005.02.10 12:09:54.700--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--corrupt object referenced through mapping: null
    [TopLink Finer]: 2005.02.10 12:09:54.700--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--corrupt object: com.sky.skynet.core.UserEvent@2c9b04ac
    [TopLink Finer]: 2005.02.10 12:09:54.700--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--validate object space.
    [TopLink Finer]: 2005.02.10 12:09:54.709--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--begin unit of work commit
    [TopLink Finer]: 2005.02.10 12:09:54.714--ClientSession(1736789279)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Connection(412999145)--begin transaction
    [TopLink Finest]: 2005.02.10 12:09:54.715--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Execute query UpdateObjectQuery(com.sky.skynet.core.User@6f32cb29)
    [TopLink Finest]: 2005.02.10 12:09:54.715--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Execute query DeleteObjectQuery(com.sky.skynet.core.UserEvent@2c9b04ac)
    [TopLink Fine]: 2005.02.10 12:09:54.716--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Connection(412999145)--DELETE FROM USEREVENTS WHERE ((EVENTDATE = ?) AND (USERID = ?))
    bind => [2020-03-20 05:00:00.0, null]
    [TopLink Finer]: 2005.02.10 12:09:54.739--ClientSession(1736789279)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--Connection(412999145)--commit transaction
    [TopLink Finer]: 2005.02.10 12:09:54.763--UnitOfWork(1638538680)--Thread(Thread[HttpRequestHandler-1810844459,5,main])--end unit of work commit
    Using
    Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)
    Oracle TopLink - 10g Developer Preview 3 (10.1.3.0 ) (Build 041116)

    Found the answer. I was using an instance of a subclass of User in order to get the cached copy of the UserEvent and thence the working copy. If instead I instantiate a new User and set its primary key userId, and then use that instead to start the process, it works. I still don't understand how, though, since after the cached copy of UserEvent is obtained I wouldn't have thought it mattered how it was obtained.
    James

  • Ignoring cache - selecting directly from database

    I have a scenario where several tables will be mapped using Toplink for the data access benefits, but will be updated ouside of the Toplink process. Obviously this behavior negates the beneift of caching in toplink and I need a reliable way to bypass the cache when selecting from these tables.
    The only method I've found in my testing to overcome this problem is to select "Always Refresh" and "Disable Cache Hits" on the related entities in the Toplink Mapping Workbench. All other configurations, including setting the identity map size to 0 will return stale instances of these objects.
    I've also tried invoking dontCheckCache() and setCacheUsage() on my query with the understanding, based on the API documentation, that the cache would be ignored for the query. In both cases the returned object was retrieved from the cache and not the database.
    While the workbench solution will suffice for my purposes, I would like to know if there are other methods of ignoring the cache. Also, I'm curious about why the query methods I've mentioned don't seem to have any affect on the source of the resulting objects.
    I am using Toplink v9.0.3

    Using "Always Refresh" and "Disable Cache Hits" is probably the best method to ensure that no cached data is every returned from queries. If you are using optimistic locking you may also use "onlyRefreshCacheIfNewerVersion" in conjunction with these.
    For the full/weak identity maps the size is only the default map size, it will grow as objects are added, so setting this to 0 will have no effect on what is cached, you could set the cache type to NoIdentityMap ("None") to achieve this, but usage of alwaysRefreshCache is a better way as is still preserves object identity.
    The query options dontCheckCache() and setCacheUsage() are in-memory querying options, they effect how cache hits are obtained, but do not effect how the objects are cached or refreshed. To refresh objects at the query level use refreshIdentityMapResult() ("Refresh"). Using refresh at the query level should also meet your needs, and may be better than setting the alwaysRefreshCache option on the descriptor as then you can control which queries refresh and which can obtain cache hits. (for example you may want to query for employees to refresh, but allow the query for the 1-1 backreference for phone numbers to obtain a cache hit). For refresh queries you can also set the refresh cascade depth.

  • Error running weblogic.ejbc with Toplink 10G

    Hi.
    I'm making some tests in order to move to Weblogic 8.1 and Toplink 10g in the near future, but I'm having some problems with my tests:
    I have built a simple entity bean based on the AccountBean used in the singlebean example from Oracle and I'm seeing this error:
    java.lang.RuntimeException: Exception [EJB - 10036]: Error during code generation: [Exception [TOPLINK-14016] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.ejb.DeploymentException
    Exception Description: An error occurred while setting up the project: [Exception [TOPLINK-43] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: Missing class for indicator field value [toplink:ejbql-call] of type [class java.lang.String].
    Descriptor: XMLDescriptor(oracle.toplink.queryframework.Call --> [DatabaseTable(call)])]
    Internal Exception: Exception [TOPLINK-43] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: Missing class for indicator field value [toplink:ejbql-call] of type [class java.lang.String].
    Descriptor: XMLDescriptor(oracle.toplink.queryframework.Call --> [DatabaseTable(call)])]
    server stacktrace is:
    Local Exception Stack:
    Exception [TOPLINK-14016] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.ejb.DeploymentException
    Exception Description: An error occurred while setting up the project: [Exception [TOPLINK-43] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: Missing class for indicator field value [toplink:ejbql-call] of type [class java.lang.String].
    Descriptor: XMLDescriptor(oracle.toplink.queryframework.Call --> [DatabaseTable(call)])]
    Internal Exception: Exception [TOPLINK-43] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: Missing class for indicator field value [toplink:ejbql-call] of type [class java.lang.String].
    Descriptor: XMLDescriptor(oracle.toplink.queryframework.Call --> [DatabaseTable(call)])
    at oracle.toplink.ejb.DeploymentException.errorCreatingProject(DeploymentException.java:111)
    at oracle.toplink.internal.ejb.cmp.CmpProjectReader.readProject(CmpProjectReader.java:76)
    at oracle.toplink.internal.ejb.cmp.ProjectDeployment.readProject(ProjectDeployment.java:219)
    at oracle.toplink.internal.ejb.cmp.ProjectDeployment.getProject(ProjectDeployment.java:208)
    at oracle.toplink.internal.ejb.cmp.PersistenceManagerBase.generateBeanSubclass(PersistenceManagerBase.java:176)
    at oracle.toplink.internal.ejb.cmp.wls.WlsCMPCodeGenerator.codeGenSubclass(WlsCMPCodeGenerator.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at weblogic.utils.compiler.CodeGenerator.processAt(CodeGenerator.java:648)
    at weblogic.utils.compiler.CodeGenerator.parse(CodeGenerator.java:587)
    at weblogic.utils.compiler.CodeGenerator.parse(CodeGenerator.java:519)
    at weblogic.utils.compiler.CodeGenerator.generateCode(CodeGenerator.java:336)
    at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:238)
    at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:197)
    at weblogic.ejb20.ejbc.EJB20CMPCompiler.generatePersistenceSources(EJB20CMPCompiler.java:88)
    at weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:245)
    at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:476)
    at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:397)
    at weblogic.ejbc20.runBody(ejbc20.java:519)
    at weblogic.utils.compiler.Tool.run(Tool.java:146)
    at weblogic.utils.compiler.Tool.run(Tool.java:103)
    at weblogic.ejbc.main(ejbc.java:29)
    This is the part of the XML that I think causes the problem:
    <opm:query name="findMessageByMessageKey" xsi:type="toplink:read-object-query">
    <opm:arguments>
    <opm:argument name="1">
    <opm:type>java.lang.Integer</opm:type>
    </opm:argument>
    <opm:argument name="2">
    <opm:type>java.lang.Integer</opm:type>
    </opm:argument>
    </opm:arguments>
    <toplink:bind-all-parameters>false</toplink:bind-all-parameters>
    <toplink:cache-statement>false</toplink:cache-statement>
    <toplink:call xsi:type="toplink:ejbql-call">
    <toplink:ejbql>SELECT OBJECT(menssage) FROM MessageBean message WHERE menssage.codMessage = ?1 AND mensaje.codIdiom = ?2</toplink:ejbql>
    </toplink:call>
    <toplink:reference-class>test.data.MessgeBean</toplink:reference-class>
    <toplink:cache-usage>conform</toplink:cache-usage>
    </opm:query>
    Of course I don't see any problem with it.
    After that I tried to run the examples but I'm seing the same error.
    I must say that I'm not using the ANT scripts but doing it "by hand" building classes and making the naked jar for the bean in order to run ejbc on it, I'm pretty confident I am not missing anything.
    I would like to know where the "ejbql-call" definition is as I have tried to find it with a grep in all the Toplink structure tree with no success. It is not clear to me how the xsd processor would find it's definition with just the: xmlns:toplink="http://xmlns.oracle.com/ias/xsds/toplink" instruction present in the header of my Message.xml file (modified based on the Account.xml of the examples).
    I'm using Sun's JDK 1.4.2 and my $CLASSPATH is:
    /opt/oracle/toplink10g/toplink/jlib/toplink.jar:/opt/oracle/toplink10g/lib/xmlparserv2.jar:/opt/oracle/toplink10g/jdbc/lib/classes12.zip:/opt/bea/wlserver8.1sp1/weblogic8.1/server/lib/weblogic.jar
    Any idea?
    Thanks in advance.
    Ignacio.

    Hi.
    Thanks I tried it and I don't get no more that message. Instead I get this stack trace:
    java.lang.RuntimeException: Exception [EJB - 10036]: Error during code generation: [Exception [TOPLINK-14016] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.ejb.DeploymentException
    Exception Description: An error occurred while setting up the project: [Exception [TOPLINK-106] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: The method [setAllQueries] on the object is throwing an exception.
    Argument: [[ReadObjectQuery(test.datos.MensajeBean), ReadObjectQuery(test.datos.MensajeBean)]]
    Internal Exception: java.lang.reflect.InvocationTargetException
    Target Invocation Exception: java.lang.NullPointerException
    Mapping: oracle.toplink.ox.CompositeCollectionMapping[queries]
    Descriptor: XMLDescriptor(oracle.toplink.publicinterface.DescriptorQueryManager --> [DatabaseTable(query-policy)])]
    Internal Exception: Exception [TOPLINK-106] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: The method [setAllQueries] on the object is throwing an exception.
    Argument: [[ReadObjectQuery(test.datos.MensajeBean), ReadObjectQuery(test.datos.MensajeBean)]]
    Internal Exception: java.lang.reflect.InvocationTargetException
    Target Invocation Exception: java.lang.NullPointerException
    Mapping: oracle.toplink.ox.CompositeCollectionMapping[queries]
    Descriptor: XMLDescriptor(oracle.toplink.publicinterface.DescriptorQueryManager --> [DatabaseTable(query-policy)])]
    server stacktrace is:
    Local Exception Stack:
    Exception [TOPLINK-14016] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.ejb.DeploymentException
    Exception Description: An error occurred while setting up the project: [Exception [TOPLINK-106] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: The method [setAllQueries] on the object is throwing an exception.
    Argument: [[ReadObjectQuery(test.datos.MensajeBean), ReadObjectQuery(test.datos.MensajeBean)]]
    Internal Exception: java.lang.reflect.InvocationTargetException
    Target Invocation Exception: java.lang.NullPointerException
    Mapping: oracle.toplink.ox.CompositeCollectionMapping[queries]
    Descriptor: XMLDescriptor(oracle.toplink.publicinterface.DescriptorQueryManager --> [DatabaseTable(query-policy)])]
    Internal Exception: Exception [TOPLINK-106] (TopLink (WLS CMP) - 10g (10.0.3) Developer Preview (Build 030902.1548)): oracle.toplink.exceptions.DescriptorException
    Exception Description: The method [setAllQueries] on the object is throwing an exception.
    Argument: [[ReadObjectQuery(test.datos.MensajeBean), ReadObjectQuery(test.datos.MensajeBean)]]
    Internal Exception: java.lang.reflect.InvocationTargetException
    Target Invocation Exception: java.lang.NullPointerException
    Mapping: oracle.toplink.ox.CompositeCollectionMapping[queries]
    Descriptor: XMLDescriptor(oracle.toplink.publicinterface.DescriptorQueryManager --> [DatabaseTable(query-policy)])
    at oracle.toplink.ejb.DeploymentException.errorCreatingProject(DeploymentException.java:111)
    at oracle.toplink.internal.ejb.cmp.CmpProjectReader.readProject(CmpProjectReader.java:76)
    at oracle.toplink.internal.ejb.cmp.ProjectDeployment.readProject(ProjectDeployment.java:219)
    at oracle.toplink.internal.ejb.cmp.ProjectDeployment.getProject(ProjectDeployment.java:208)
    at oracle.toplink.internal.ejb.cmp.PersistenceManagerBase.generateBeanSubclass(PersistenceManagerBase.java:176)
    at oracle.toplink.internal.ejb.cmp.wls.WlsCMPCodeGenerator.codeGenSubclass(WlsCMPCodeGenerator.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at weblogic.utils.compiler.CodeGenerator.processAt(CodeGenerator.java:648)
    at weblogic.utils.compiler.CodeGenerator.parse(CodeGenerator.java:587)
    at weblogic.utils.compiler.CodeGenerator.parse(CodeGenerator.java:519)
    at weblogic.utils.compiler.CodeGenerator.generateCode(CodeGenerator.java:336)
    at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:238)
    at weblogic.utils.compiler.CodeGenerator.generate(CodeGenerator.java:197)
    at weblogic.ejb20.ejbc.EJB20CMPCompiler.generatePersistenceSources(EJB20CMPCompiler.java:88)
    at weblogic.ejb20.ejbc.EJBCompiler.doCompile(EJBCompiler.java:245)
    at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:476)
    at weblogic.ejb20.ejbc.EJBCompiler.compileEJB(EJBCompiler.java:397)
    at weblogic.ejbc20.runBody(ejbc20.java:519)
    at weblogic.utils.compiler.Tool.run(Tool.java:146)
    at weblogic.utils.compiler.Tool.run(Tool.java:103)
    at weblogic.ejbc.main(ejbc.java:29)
    What I don't understand is: if examples include that toplink:ejbql-call it should be declared into the xsd isn't it? It will be included in the future (final) release then?
    Thanks again.
    Ignacio.

  • Toplink Profiler -- ReadAllQuery

    I'm using the toplink oracle.toplink.tools.profiler.PerformanceProfiler to profile out code in hopes to speed it up our application. I let the profiler run for two days on our staging server under light load. Several of the entries are very interesting, this ReadAllQuery took 10.5 seconds. Most of the time was spend in operations: object building and query prepare. It looks like the SQL execute was only 151 milliseconds. When I run the generated SQL against the database it's extremely quick.
    Profile(ReadAllQuery,
    class=com.attask.model.RKProject,
    number of objects=1,
    total time=10554,
    local time=10554,
    profiling time=140,
    cache=920,
    sql prepare=233,
    DescriptorEvents=1,
    query prepare=2454,
    sql execute=151,
    object building=6384,
    logging=44,
    sql generation=640,
    time/object=10554,
    SQL that was generated:
    SELECT t0.ID, t0.RESOURCEPOOLID, t0.HASMSGS, t0.OWNERID, t0.BUDGETEDSTARTDATE, t0.PLANNEDCOMPLETIONDATE, t0.PROGSTAT, t0.ALIGNMENT, t0.SCHEDULEMODE, t0.COND, t0.LASTNOTEID, t0.BUDGETEDCOMPLETIONDATE, t0.ENTEREDBYID, t0.FIXEDREVENUE, t0.TEMPLATEID, t0.ESTSTARTDATE, t0.MILESTONEPATHID, t0.HASRESOLVABLE, t0.PROJECTEDSTARTDATE, t0.CSI, t0.AUTOCOMPLETETYPE, t0.POPACCOUNTID, t0.CPI, t0.PLANNEDCOST, t0.DURMINUTES, t0.NUMOPENOPTASKS, t0.VERSION, t0.BENEFIT, t0.GROUPID, t0.ACTUALDURMINUTES, t0.CATEGORYID, t0.ACTUALCOMPLETIONDATE, t0.HASNOTES, t0.ISBUDGETED, t0.SCHEDULEID, t0.ACTUALSTARTDATE, t0.HASCALCERROR, t0.PIMETHOD, t0.LASTUPDATEDBYID, t0.PERCENTCOMPLETE, t0.UPDATETYPE, t0.LASTUPDATEDATE, t0.CUSTOMERID, t0.ACTUALCOST, t0.DISPLAYORDER, t0.BILLEDREVENUE, t0.COMPANYID, t0.FIXEDCOST, t0.HASBUDGETCONFLICT, t0.AUDITTYPES, t0.PLANNEDSTARTDATE, t0.EXTREFID, t0.LASTCALCDATE, t0.NAME, t0.EAC, t0.PROJECTEDCOMPLETIONDATE, t0.ACTUALREVENUE, t0.BUDGET, t0.PRIORITY, t0.CONDTYPE, t0.ACTUALWORK, t0.ENTRYDATE, t0.SPI, t0.PLANNEDREVENUE, t0.STATUS, t0.WORKREQUIRED, t0.RISK, t0.ESTCOMPLETIONDATE, t0.HASDOCUMENTS, t0.QUEUEID, t0.DESCRIPTION FROM T_PROJECTS t0, T_CUSTOMERS t1 WHERE ((((t0.LASTCALCDATE < ?) AND (t1.ISDISABLED = ?)) AND (t0.UPDATETYPE IN (?, ?))) AND (t1.ID = t0.CUSTOMERID)) ORDER BY t0.LASTCALCDATE ASC
    bind => [1195110000000, false, AUTO, ATYO]
    There isn't any special about this operation, in fact it runs every hour on a timer. Normally the results this operation is:
    Profile(ReadAllQuery,
    class=com.attask.model.RKProject,
    number of objects=1,
    total time=33,
    local time=33,
    sql prepare=1,
    query prepare=1,
    sql execute=31,
    time/object=33,
    objects/second=30,
    Notice it doesn't even have those operations. I can even clear the database cache,
    oracle.toplink.threetier.Server.getIdentityMapAccessor().initializeAllIdentityMaps();
    and the operation is fast.
    The question is, What causes this slow down. Could this be a garbage collection issue? Does anyone have any ideas? This wouldn't be a problem, except that it happens too often.
    Toplink version 10.1.3.3

    I finally found the issue: the oracle.dms.instrument.DMSConsole is never initialized by TopLink. I have to do it manually :
    try {
         new DMSConsole().init(null);
    } catch (DMSError e) {
         e.printStackTrace();
    }because TopLink's DMSPerformanceProfiler getthe sensor level from the DMSConsole using the following method:
    DMSConsole.getSensorWeight()and the DMSConsole's sensor weight is read from System properties only during initialization.
    I hope this has been corrected in the TopLink versions newer that the one I use.

Maybe you are looking for

  • How to enable forwarding apple ID address to different mail app?

    I want to enable forwarding of my apple ID email address to a different email app.  How do I set up apple mail to forward emails to a different app like Gmail, etc?

  • Help: Switching To Firewire

    I am going to swtich to Firewire, does it have to be the Adaptec 4300? After I install the FW card,do I need to reinstall iTunes?

  • Oracle Workflow version

    I intend to use process flows in OWB 10.2.0.5 (with Oracle Database 9.2) and in OWB 11.1 (with Oracle database 11.1). I'm having difficulties to find the appropriate versions of Oracle Workflow I should install in each case. Does anyone know where ca

  • Problem viewing several purchased itunes store videos.

    I purchased several videos (episodes of lost)and they show up in the movie download section as gray boxes and I'm unable to play them. in the itunes download folder they show up as a file titled "download" with an info file. the other videos I downlo

  • Passing a Hash Map in a Custom Workflow.

    I have a workflow WF_CUSTOM_TXT which inputs credentials such as resource name, type, connection string and then I am passing the attributes as a Hash Map: - Map attributes =new HashMap(); attributes.put("firstname", "Nakul"); attributes.put("lastnam