This discussion is archived
13 Replies Latest reply: Apr 9, 2013 6:46 AM by 399257 RSS

Toplink grid + Eclipselink JPA issue

dflint Newbie
Currently Being Moderated
Hello,

I'm trying to run example from this link: http://www.oracle.com/technetwork/middleware/toplink/examples-325517-en-ca.html
About JPA Grid Entity.
I do next steps:
1. create db with CreateDatabase class
2. run coherence instance with StartCacheServer clas
3. persist Employee object with InsertExample class

Now I'm trying to test standard JPA API functions.
I'm running next code:

.....................................
// Restrict Coherence to localhost
System.setProperty("tangosol.coherence.wka", InetAddress.getLocalHost().getHostAddress());

// Disable local storage--need to start independent CacheServer
System.setProperty("tangosol.coherence.distributed.localstorage","false");

EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee-pu");
EntityManager em = emf.createEntityManager();
Employee employee1 = em.find(Employee.class, 201);
List<Employee> employees = em.createNamedQuery("Employee.findByLastNameLike").setParameter("lastName", "Smit%").getResultList();

System.out.println("<<<<<<<<<<<<<<<<<<<<<< EQUAS:"+employee1.equals(employees.get(0)));
          
emf.close();
.........................................

As result I see next output: "<<<<<<<<<<<<<<<<<<<<<< EQUAS:false"

Please explaine me why Employee objects are not same in "find" result and "query" result.
If I run this example without Coherence and Toplink Grid I see that objects are same.

Tx,
  • 1. Re: Toplink grid + Eclipselink JPA issue
    ShaunSmith Explorer
    Currently Being Moderated
    Not sure why you're seeing this. We'll investigate and see if we can reproduce..

    --Shaun                                                                                                                                                                                       
  • 2. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    Hi Shaun,

    Do you confirm that it's not correct Toplink Grid behavior?
  • 3. Re: Toplink grid + Eclipselink JPA issue
    399257 Explorer
    Currently Being Moderated
    That is correct, this is unexpected behaviour. The entities loaded through the query are still managed however so just using a query or using a query then a find there would be no indication that there were any issues. As a workaround you could perform a read-only query using the queryHint but the results of that query are not managed and a find would be needed to get the managed version.
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
  • 4. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    Hello Gordon,

    Thank you for response.
    I understood what you mean.
    Do you plan to fix this issue in the future releases?

    One more question.
    From this old thread "https://forums.oracle.com/forums/thread.jspa?threadID=719027" I understood that for that moment TLG didn't support Coherence transactions.
    What about currrent TL release?

    The next question.
    I'm trying to test JPA lock.
    I'm running same example on different VMs in debug mode

    VM 1 doing next steps:

    .......................
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("employee-pu");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Employee employee = em.find(Employee.class, 1, LockModeType.PESSIMISTIC_WRITE);
    .......................


    VM 2 doing same steps but it is hanging on last step


    VM 1 is continuing:

    .......................
    em.getTransaction().commit();
    em.close();
    emf.close();
    .......................


    VM 2 can continue if VM 1 will be completed at all.
    Please explain me why VM2 can't continue when VM1 invoke "em.getTransaction().commit();" or "em.close();"?

    Tx a lot

    Edited by: dflint on 27.02.2013 4:53
  • 5. Re: Toplink grid + Eclipselink JPA issue
    399257 Explorer
    Currently Being Moderated
    Yes, this issue is target for the next release.
    TopLink Grid does not support Coherence transactional caches and priority for that feature is very low. There are restrictions with the Coherence transactional caches that limit their usefulness.

    With your locking question it is not clear what problem you are experiencing. VM2 will not be able to update any tables mapped to the Employee class and will block (hang) at that point as long as VM1's transaction is open. That is how pessimistic locking is intended to work.
  • 6. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    Hello Gordon,

    I use "grid-entity" configuration. So as I understand TLG will lock object in Coherence and there is no pessimistic lock on DB table in this case.
    But when VM1 commits transaction ("em.getTransaction().commit();") and closes EntityManager instance ("em.close();") lock is not released. So VM2 continues to block.
  • 7. Re: Toplink grid + Eclipselink JPA issue
    399257 Explorer
    Currently Being Moderated
    Pessimistic locks are still acquired on the Database even when using Grid Entity. This is to ensure complex queries will still result in suffecient locking. TopLink Grid does not acquire any locks within Coherence. On EM.close() the locks on the database should be released so I am not sure what could be blocking VM2. Where is VM2 blocked?
  • 8. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    Hello Gordon,

    Sorry for later post.
    When VM1 calls "Employee employee = em.find(Employee.class, 1, LockModeType.PESSIMISTIC_WRITE);" I don't see any lock query in DB. But lock is acquired.
    Anyway you are right when VM1 calls "em.close();" any lock should be released. But VM2 is still blocked on the call: "Employee employee = em.find(Employee.class, 1, LockModeType.PESSIMISTIC_WRITE);"
  • 9. Re: Toplink grid + Eclipselink JPA issue
    399257 Explorer
    Currently Being Moderated
    Get a thread dump at the point the VM is stuck. This will let us know where it is stuck specifically.
  • 10. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    It seems I can't call "em.find" in different VMs also without any lock.
    I mean two different VMs can't call "Employee employee = em.find(Employee.class, 1);" in parallel.
    So it's not pessimistic lock issue. I don't know what is it.
  • 11. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    Blank msg
    See next post
  • 12. Re: Toplink grid + Eclipselink JPA issue
    dflint Newbie
    Currently Being Moderated
    Hello Gordon,

    I found problem with locking. It was debug issue. VM2 is locked when VM1 first calls "Employee employee = em.find(Employee.class, 1);" and then it is suspended on breakpoint.
    But I'm still don't see any locks in DB.
    So currently I need to get answers to the questions to decide if we can use TLG in our project or not.

    Here are these questions:

    1. There is the opened question about locking. How can I lock objects through JPA + TLG?
    If it's possible to lock through DB only the next question becomes opened:
    If I use "grid-entity" configuration with write-behind Coherence cache how can TLG guarantee locking in DB?
    I mean we can have situation when some recently persisted object is not stored in DB because cache is "write-behind".




    2. When I just call "Employee employee = em.find(Employee.class, 1);" I see always in the log two requests to coherence.
    I see two records in the log something like this:

    ...............................
    [EL Fine]: Coherence(Employee)::Get: 1 result: Employee(1: Smith, Bob)
    [EL Fine]: Coherence(Employee)::Get: 1 result: Employee(1: Smith, Bob)
    ...............................

    Is it expected behavior?




    3. Now I would like to use cache warming/pre-loading feature.
    I have two records in the "tlg_ge_employee" DB table:

    ID FIRSTNAME LASTNAME VERSION ADDRESS_ID

    1     Bob     Smith null null
    2     Robert Johnson null null

    Next I call query with hint to warm up the cache:

    ...............................
    Query query = em.createQuery("select e from Employee e");
    query.setHint(QueryHints.QUERY_REDIRECTOR, new IgnoreDefaultRedirector());
    query.getResultList();
    ...............................

    and what I see in the log:

    ..........................................................................................................
    [EL Info]: EclipseLinkCacheLoader-employee-pu login successful
    [EL Fine]: Connection(1033259924)--SELECT ID, FIRSTNAME, LASTNAME, VERSION, ADDRESS_ID FROM TLG_GE_EMPLOYEE WHERE (ID = ?)
         bind => [1]
    [EL Fine]: Coherence(Employee)::Get: 1 result: Employee(1: Smith, Bob)
    [EL Fine]: Connection(1033259924)--SELECT ID, FIRSTNAME, LASTNAME, VERSION, ADDRESS_ID FROM TLG_GE_EMPLOYEE WHERE (ID = ?)
         bind => [2]
    [EL Fine]: Coherence(Employee)::Get: 2 result: Employee(2: Johnson, Robert)
    ..........................................................................................................

    Does it mean TLG will get all objects from Coherence one by one?
    Is it possible to warm-up cache using one batch-query?
    Is it possible to warm-up cache without fetching all data to client?


    Tx in advance
  • 13. Re: Toplink grid + Eclipselink JPA issue
    399257 Explorer
    Currently Being Moderated
    Hello, I apologize for taking a while to respond please find your answers below:

    When using Coherence write-behind with "grid-entity" there is no guarantee of database locking or order of operations on the database and recently persisted objects may not be written to the database at any particular point in time. When using Coherence write-behind the assumption is that Coherence is your datasouce and the database is secondary.

    I am surprised that you see those double Coherence gets when performing a find, it is not present in our testing. What version of TopLink-Grid are you using?

    In the version you are using TopLink-Grid does resolve query results against the cache one entity at time. This is expected to be resolved in the next version of TopLink-Grid.
    But if you apply the QueryHint javax.persistence.cache.retrieveMode = BYPASS then the cache check should not occur and the results will only be pushed to Coherence.
    Batch queries can be used to improve database query time.

    At this time there is no functionality in Coherence or TopLinkGrid to cause a bulk load of the data.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points