/**********************************************************************
Copyright (c) 2016 Andy Jefferson and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:
    ...
**********************************************************************/
package org.datanucleus.tests;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import org.datanucleus.api.jpa.NucleusJPAHelper;
import org.datanucleus.tests.JPAPersistenceTestCase;
import org.jpox.samples.annotations.nondurableidentity.NonDurableIDHolder;

/**
 * Series of tests for Datastore Identity.
 */
public class NonDurableIdentityTest extends JPAPersistenceTestCase
{
    public NonDurableIdentityTest(String name)
    {
        super(name);
    }

    /**
     * Basic test.
     */
    public void testBasic()
    {
        try
        {
            EntityManager em = getEM();
            EntityTransaction tx = em.getTransaction();
            Object id = null;
            try
            {      
                tx.begin();
                NonDurableIDHolder holder = new NonDurableIDHolder("First Holder");
                em.persist(holder);
                em.flush();
                id = NucleusJPAHelper.getObjectId(holder);
                assertNull(id);
                tx.commit();
            }
            catch (Exception e)
            {
                LOG.error(e);
                e.printStackTrace();
                fail(e.getMessage());
            }
            finally
            {
                if (tx.isActive())
                {
                    tx.rollback();
                }
                em.close();
            }
            emf.getCache().evictAll();

        }
        finally
        {
            clean(NonDurableIDHolder.class);
        }
    }
}
@@ -798,24 +798,50 @@
 s.tests;%0D%0A%0D%0A
+import java.util.List;%0D%0A%0D%0A
 import javax
@@ -865,24 +865,24 @@
 tyManager;%0D%0A
-
 import javax
@@ -913,16 +913,49 @@
 action;%0D
+%0Aimport javax.persistence.Query;%0D
 %0A%0D%0Aimpor
@@ -2003,47 +2003,30 @@
 ror(
-e);%0D%0A                e.printStackTrace(
+%22Exception in test%22, e
 );%0D%0A
@@ -2307,24 +2307,809 @@
 ctAll();%0D%0A%0D%0A
+            em = emf.createEntityManager();%0D%0A            tx = em.getTransaction();%0D%0A            try%0D%0A            %7B      %0D%0A                tx.begin();%0D%0A                Query q = em.createQuery(%22SELECT h FROM NonDurableIDHolder h%22);%0D%0A                List%3CNonDurableIDHolder%3E results = q.getResultList();%0D%0A                assertNotNull(results);%0D%0A                assertEquals(1, results.size());%0D%0A%0D%0A                tx.commit();%0D%0A            %7D%0D%0A            catch (Exception e)%0D%0A            %7B%0D%0A                LOG.error(%22Exception in test%22, e);%0D%0A                fail(e.getMessage());%0D%0A            %7D%0D%0A            finally%0D%0A            %7B%0D%0A                if (tx.isActive())%0D%0A                %7B%0D%0A                    tx.rollback();%0D%0A                %7D%0D%0A                em.close();%0D%0A            %7D%0D%0A
         %7D%0D%0A 

add query