6 Replies Latest reply: Jun 26, 2012 10:16 AM by 878913 RSS

    JPA on the Grid API

    878913
      Hi All , I am working with JPA on the TopLink grid with Coherence my Intention is to put the data in cache as well as in database , when the database get shutdown i have to get the data from cache ..

      so for that i have created cache store to store the data in the cache its working fine when database is on startup mode , when db shutdown its unable to pick the data ...showing error
      2012-06-18 21:21:08.173/7.234 Oracle Coherence GE 3.7.1.0 <Error> (thread=DistributedCache:EclipseLinkJPA, member=1): BackingMapManager com.tangosol.net.DefaultConfigurableCacheFactory$Manager: failed to instantiate a cache: Employe
      2012-06-18 21:21:08.173/7.234 Oracle Coherence GE 3.7.1.0 <Error> (thread=DistributedCache:EclipseLinkJPA, member=1):
      (Wrapped: Missing or inaccessible constructor "oracle.eclipselink.coherence.standalone.EclipseLinkJPACacheStore(String,String)"
      <class-scheme>
      <!--
      Since the client code is using Coherence API we need the "standalone"
      version of the cache loader
      -->
      <class-name>oracle.eclipselink.coherence.standalone.EclipseLinkJPACacheStore</class-name>
      <init-params>
      <init-param>
      <param-type>java.lang.String</param-type>
      <param-value>Employe</param-value>
      </init-param>
      <init-param>
      <param-type>java.lang.String</param-type>
      <param-value>CacheStoreProject</param-value>
      </init-param>
      </init-params>
      </class-scheme>) java.lang.reflect.InvocationTargetException
           at com.tangosol.util.Base.ensureRuntimeException(Base.java:288)
           at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2652)
           at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2536)
           at com.tangosol.net.DefaultConfigurableCacheFactory.instantiateAny(DefaultConfigurableCacheFactory.java:3476)
           at com.tangosol.net.DefaultConfigurableCacheFactory.instantiateCacheStore(DefaultConfigurableCacheFactory.java:3324)
           at com.tangosol.net.DefaultConfigurableCacheFactory.instantiateReadWriteBackingMap(DefaultConfigurableCacheFactory.java:1753)
           at com.tangosol.net.DefaultConfigurableCacheFactory.configureBackingMap(DefaultConfigurableCacheFactory.java:1500)
           at com.tangosol.net.DefaultConfigurableCacheFactory$Manager.instantiateBackingMap(DefaultConfigurableCacheFactory.java:4111)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$Storage.instantiateBackingMap(PartitionedCache.CDB:22)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$Storage.setCacheName(PartitionedCache.CDB:25)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$ServiceConfig$ConfigListener.entryInserted(PartitionedCache.CDB:17)
           at com.tangosol.util.MapEvent.dispatch(MapEvent.java:266)
           at com.tangosol.util.MapEvent.dispatch(MapEvent.java:226)
           at com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:567)
           at com.tangosol.util.ObservableHashMap.dispatchEvent(ObservableHashMap.java:229)
           at com.tangosol.util.ObservableHashMap$Entry.onAdd(ObservableHashMap.java:270)
           at com.tangosol.util.SafeHashMap.put(SafeHashMap.java:244)
           at com.tangosol.coherence.component.util.ServiceConfig$Map.put(ServiceConfig.CDB:43)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$StorageIdRequest.onReceived(PartitionedCache.CDB:45)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onMessage(Grid.CDB:34)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:33)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.PartitionedService.onNotify(PartitionedService.CDB:3)
           at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache.onNotify(PartitionedCache.CDB:3)
           at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
           at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.reflect.InvocationTargetException
           at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
           at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
           at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
           at java.lang.reflect.Constructor.newInstance(Unknown Source)
           at com.tangosol.util.ClassHelper.newInstance(ClassHelper.java:694)
           at com.tangosol.run.xml.XmlHelper.createInstance(XmlHelper.java:2611)
           ... 23 more
      Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: java.sql.SQLException: Listener refused the connection with the following error:
      ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
      The Connection descriptor used by the client was:
      localhost:1521:xe

      Error Code: 0
           at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
           at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
           at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getServerSession(EntityManagerFactoryDelegate.java:219)
           at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:247)
           at org.eclipse.persistence.jpa.JpaHelper.getServerSession(JpaHelper.java:193)
           at oracle.eclipselink.coherence.standalone.EclipseLinkJPACacheLoader.<init>(EclipseLinkJPACacheLoader.java:70)
           at oracle.eclipselink.coherence.standalone.EclipseLinkJPACacheStore.<init>(EclipseLinkJPACacheStore.java:26)
           ... 29 more
      Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
      Internal Exception: java.sql.SQLException: Listener refused the connection with the following error:
      ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
      The Connection descriptor used by the client was:
      localhost:1521:xe

      Error Code: 0
           at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
           at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
           at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
           at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
           at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:584)
           at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
           at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
           ... 35 more
      Caused by: java.sql.SQLException: Listener refused the connection with the following error:
      ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
      The Connection descriptor used by the client was:
      localhost:1521:xe

           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
           at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
           at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
           at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
           at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
           at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
           at java.sql.DriverManager.getConnection(Unknown Source)
           at java.sql.DriverManager.getConnection(Unknown Source)
           at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:98)
           ... 39 more
      New Employe from cache is: null
      program for put and get the data from cache
      package com.cachestore.example;

      import com.oracle.employe.Employe;

      import com.tangosol.net.CacheFactory;
      import com.tangosol.net.NamedCache;

      public class PutGetData {
           public static void main(String[] args) {
                
                System.setProperty("tangosol.coherence.distributed.localstorage","true");

                // Get the cache--name is same as Entity
                NamedCache employeeCache = CacheFactory.getCache("Employe");
                Employe employee = new Employe();
                employee.setId(4);
                employee.setFirstname("rambabu");
                employee.setLastname("davuluri");
                
                //employeeCache.put(employee.getId(), employee);
                
                // Getting an object from cache produces no SQL
                System.out.println("New Employe from cache is: " + employeeCache.get(4));
                
                
           
      }
      Thanks
        • 1. Re: JPA on the Grid API
          ShaunSmith
          What's happening is the JPA cache store is failing on creation/initialization due to its inability to connect to the database.

          Can you describe the behaviour you're expecting? Are you saying you want an "optional" cache store that works when the database is up and silently ignores problems when the database is down? It would still have to fail on write otherwise Coherence write behind will believe the writes have been successfully performed and won't get retried. On a get() with a cache miss, would retuning a null from the cache store be what you want? Your application will be lead to believe that there is no object with the specified key when in reality there may be such an object that just doesn't happen to have been read into cache yet. Perhaps this is acceptable if you were to fully warm your caches.


          --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
          • 2. Re: JPA on the Grid API
            878913
            Thanks for reply,...Shaun my requirement is to i want to get the data from cache even the database got shutdown....

            here we are storing the data into cache as well as database also...

            can u pls tell me how approach to this task ......

            Thanks
            • 3. Re: JPA on the Grid API
              ShaunSmith
              The EclipseLinkJPACacheStore will fail if it cannot login but a way for you to get the behavior you're looking for is to write your own implementation of com.tangosol.net.cache.CacheStore that wraps oracle.eclipselink.coherence.standalone.EclipseLinkJPACacheStore. You'd simply delegate each call to the embedded EclipseLinkJPACacheStore and wrap each call in an exception handler. You'd also have to wrap the creation of the EclipseLinkJPACacheStore with an exception handler as creation will fail if the database is down, as you've seen.

              --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
              • 4. Re: JPA on the Grid API
                878913
                Hi shaun thanks for reply...can u please tell me how to configure the eclipse link store by using cache store where i can configure these settings....


                to get the data from cache even my database got shutdown.

                How to approach to this task.


                thanks.
                • 5. Re: JPA on the Grid API
                  ShaunSmith
                  The functionality you're looking for is not available out of the box and, as I'd pointed out in a previous post, the semantics you're looking for are not clear. Fortunately the CacheStore API is very small and you can easily implement you're own CacheStore that wraps a EclipseLinkJPACacheStore. If you truly want to simply ignore loss of database connectivity you could handle and suppress exceptions coming back from a EclipseLinkJPACacheStore in your wrapper.

                  http://docs.oracle.com/cd/E24290_01/coh.371/e22843/com/tangosol/net/cache/CacheLoader.html
                  http://docs.oracle.com/cd/E24290_01/coh.371/e22843/com/tangosol/net/cache/CacheStore.html

                  --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
                  • 6. Re: JPA on the Grid API
                    878913
                    Thanks shaun..its usefull...