dev@glassfish.java.net

[Fwd: persistence Digest 1 Nov 2005 22:43:15 -0000 Issue 8]

From: Carla Mott <Carla.Mott_at_Sun.COM>
Date: Tue, 01 Nov 2005 15:06:32 -0800

-- 
Carla Mott
Sun Microsystems		
carla.mott_at_sun.com

attached mail follows:



Content-type: text/plain; charset=us-ascii


persistence Digest 1 Nov 2005 22:43:15 -0000 Issue 8

Topics (messages 43 through 57):

Re: SQLException running EJBQL query selecting association field
        43 by: Gordon Yorke
        44 by: Michael Bouschen
        50 by: Michael Bouschen

Re: Persistence Test Integrated in QuickLook
        45 by: Marina Vatkina
        46 by: Deepa Singh
        47 by: Marina Vatkina
        48 by: Deepa Singh
        49 by: Gordon Yorke
        56 by: Deepa Singh
        57 by: Marina Vatkina

Re: Question about EJBQL HAVING clause
        51 by: Michael Bouschen
        52 by: Michael Bouschen

Question about EJBQL queries with multiple expressions in the SELECT clause
        53 by: Michael Bouschen

Re: Multiple Return types EJBQL
        54 by: Michael Bouschen
        55 by: Gordon Yorke

Administrivia:

To subscribe to the digest, e-mail:
        persistence-digest-subscribe_at_glassfish.dev.java.net

To unsubscribe from the digest, e-mail:
        persistence-digest-unsubscribe_at_glassfish.dev.java.net

To post to the list, e-mail:
        persistence_at_glassfish.dev.java.net


----------------------------------------------------------------------


Content-type: message/rfc822

Date: Mon, 31 Oct 2005 14:34:57 -0500
From: "Gordon Yorke" <gordon.yorke_at_oracle.com>
Subject: RE: SQLException running EJBQL query selecting association field
To: "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>,
 "Tom Ware" <tom.ware_at_oracle.com>
Message-id: <20051031143457594.00000002552_at_gyorke-pc2>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: QUOTED-PRINTABLE

Hello Michael,
=09I am not familliar enough with your changes to the EJBQL parser to=
 point out what is causing this issue but I can explain why this erro=
r is occuring within TopLink.
=09The Reference Class has been set to Order on the query but the ref=
erence class should be Customer. I think the old parser code used to=
 evaluate the path expressions to determine what the real target type=
 is. (ie Order.customer is really selecting customers).
=09
--Gordon

-----Original Message-----
=46rom: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
Sent: Monday, October 31, 2005 9:11 AM
To: Tom Ware
Cc: persistence_at_glassfish.dev.java.net
Subject: SQLException running EJBQL query selecting association field


Hi Tom,

I run into a problem with an EJBQL query selecting an association fie=
ld:

EJBQL: SELECT o.customer FROM Order o
SQL: SELECT CMP3_ORDER.ORDER_ID, CMP3_ORDER.SHIP_ADDR,
               CMP3_ORDER.CREATION_DATE, CMP3_ORDER.TOTAL_PRICE,
               CMP3_ORDER.ORDER_VERSION, CMP3_ORDER.QUANTITY,
               CMP3_ORDER.ITEM_ID, CMP3_ORDER.CUST_ID
        FROM CMP3_CUSTOMER t0, CMP3_ORDER t1
        WHERE (t0.CUST_ID (+) =3D t1.CUST_ID)
Running the above query on a Oracle database results in a SQLExceptio=
n:
ORA-00904: "CMP3_ORDER"."CUST_ID": invalid identifier.

Any idea?

I filed an glassfish issue and assigned to you:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=3D67

Regards Michael




Content-type: message/rfc822

Date: Mon, 31 Oct 2005 21:29:00 +0100
From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Subject: Re: SQLException running EJBQL query selecting association field
To: persistence_at_glassfish.dev.java.net
Cc: Tom Ware <tom.ware_at_oracle.com>
Message-id: <43667E8C.4070601_at_sun.com>
MIME-version: 1.0
Content-type: text/plain; charset=ISO-8859-1; format=flowed
Content-transfer-encoding: 7BIT

Hi Gordon,

thanks for the hint. I understand that the query should execute ok if
the reference class is set to the type of the association field
(Customer in this case). I take a look at the parser and try to change
the reference class.

Regards Michael

>Hello Michael,
> I am not familliar enough with your changes to the EJBQL parser to point out what is causing this issue but I can explain why this error is occuring within TopLink.
> The Reference Class has been set to Order on the query but the reference class should be Customer. I think the old parser code used to evaluate the path expressions to determine what the real target type is. (ie Order.customer is really selecting customers).
>
>--Gordon
>
>-----Original Message-----
>From: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
>Sent: Monday, October 31, 2005 9:11 AM
>To: Tom Ware
>Cc: persistence_at_glassfish.dev.java.net
>Subject: SQLException running EJBQL query selecting association field
>
>
>Hi Tom,
>
>I run into a problem with an EJBQL query selecting an association field:
>
>EJBQL: SELECT o.customer FROM Order o
>SQL: SELECT CMP3_ORDER.ORDER_ID, CMP3_ORDER.SHIP_ADDR,
> CMP3_ORDER.CREATION_DATE, CMP3_ORDER.TOTAL_PRICE,
> CMP3_ORDER.ORDER_VERSION, CMP3_ORDER.QUANTITY,
> CMP3_ORDER.ITEM_ID, CMP3_ORDER.CUST_ID
> FROM CMP3_CUSTOMER t0, CMP3_ORDER t1
> WHERE (t0.CUST_ID (+) = t1.CUST_ID)
>Running the above query on a Oracle database results in a SQLException:
>ORA-00904: "CMP3_ORDER"."CUST_ID": invalid identifier.
>
>Any idea?
>
>I filed an glassfish issue and assigned to you:
>https://glassfish.dev.java.net/issues/show_bug.cgi?id=67
>
>Regards Michael
>
>
>
>



Content-type: message/rfc822

Date: Tue, 01 Nov 2005 14:34:11 +0100
From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Subject: Re: SQLException running EJBQL query selecting association field
To: persistence_at_glassfish.dev.java.net
Cc: Tom Ware <tom.ware_at_oracle.com>
Message-id: <43676ED3.9060401_at_sun.com>
MIME-version: 1.0
Content-type: multipart/mixed; boundary="Boundary_(ID_LUC3RmW3+gVPZhyPLKIT5w)"

This is a multi-part message in MIME format.

--Boundary_(ID_LUC3RmW3+gVPZhyPLKIT5w)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi Gordon,

The parser has been changed in order to fix a problem with multiple
navigations in the select clause expression, e.g. "SELECT
o.customer.name FROM Order o". This query ran into an exception "Invalid
query key [customer] in expression.". The fix changed class SelectNode
to use the class of the left most node of the select expression as
reference class. This seems to not work if the select expression selects
an association field.

I think I found a fix. I changed the code in SelectNode and check
whether the select expression is selecting a direct-to-field. If yes, I
use the code added in the previous fix, meaning the class of the left
most node determines the reference class. If not, I use the class of the
selected field as reference class (which is what the old parser code did).

Attached you find the changes of SelectNode.java in 'cvs diff -u' output
format.

Thanks!

Regards Michael

> Hello Michael,
> I am not familliar enough with your changes to the EJBQL parser to point out what is causing this issue but I can explain why this error is occuring within TopLink.
> The Reference Class has been set to Order on the query but the reference class should be Customer. I think the old parser code used to evaluate the path expressions to determine what the real target type is. (ie Order.customer is really selecting customers).
>
> --Gordon
>
> -----Original Message-----
> From: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
> Sent: Monday, October 31, 2005 9:11 AM
> To: Tom Ware
> Cc: persistence_at_glassfish.dev.java.net
> Subject: SQLException running EJBQL query selecting association field
>
>
> Hi Tom,
>
> I run into a problem with an EJBQL query selecting an association field:
>
> EJBQL: SELECT o.customer FROM Order o
> SQL: SELECT CMP3_ORDER.ORDER_ID, CMP3_ORDER.SHIP_ADDR,
> CMP3_ORDER.CREATION_DATE, CMP3_ORDER.TOTAL_PRICE,
> CMP3_ORDER.ORDER_VERSION, CMP3_ORDER.QUANTITY,
> CMP3_ORDER.ITEM_ID, CMP3_ORDER.CUST_ID
> FROM CMP3_CUSTOMER t0, CMP3_ORDER t1
> WHERE (t0.CUST_ID (+) = t1.CUST_ID)
> Running the above query on a Oracle database results in a SQLException:
> ORA-00904: "CMP3_ORDER"."CUST_ID": invalid identifier.
>
> Any idea?
>
> I filed an glassfish issue and assigned to you:
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=67
>
> Regards Michael
>
>


--Boundary_(ID_LUC3RmW3+gVPZhyPLKIT5w)
Content-type: text/plain; name=SelectNode.patch
Content-transfer-encoding: 7BIT
Content-disposition: inline; filename=SelectNode.patch

Index: SelectNode.java
===================================================================
RCS file: /cvs/glassfish/entity-persistence/src/java/oracle/toplink/essentials/internal/parsing/SelectNode.java,v
retrieving revision 1.2
diff -u -r1.2 SelectNode.java
--- SelectNode.java 18 Oct 2005 19:39:17 -0000 1.2
+++ SelectNode.java 1 Nov 2005 13:31:31 -0000
@@ -310,7 +310,9 @@
    * @return the class this query is querying for
    */
     public Class getReferenceClass(GenerationContext context) {
- return resolveBaseClass(context);
+ return selectingDirectToField(context) ?
+ resolveBaseClass(context) :
+ resolveClass(context);
     }
 
     /**

--Boundary_(ID_LUC3RmW3+gVPZhyPLKIT5w)--


Content-type: message/rfc822

Date: Mon, 31 Oct 2005 13:06:28 -0800
From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Subject: Re: Persistence Test Integrated in QuickLook
To: Deepa Singh <Deepa.Singh_at_Sun.COM>
Cc: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>,
 "Shelly (Donna) McGowan" <Shelly.McGowan_at_Sun.COM>,
 Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>,
 Michael Bouschen <Michael.Bouschen_at_Sun.COM>,
 Sailaja Rao Gangaraju <Sailaja.Rao_at_Sun.COM>,
 persistence <persistence_at_glassfish.dev.java.net>
Message-id: <43668754.8010103_at_Sun.COM>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT

Hi Deepa,

(CC-ing persistence)

Can it be that the record is already there? TopLink code might be
caching results of a previous run. Keep in mind that CMP code uses
completely different code for persistence runtime.

thanks,
-marina

Deepa Singh wrote On 10/31/05 12:52,:
> Hi Marina,
> Persistence Quicklook tests is integrated into GlassFish quicklook test
> base.
> glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>
> There is only one thing missing, when I run my test (execute only client
> )twice (after dropping table and re-creating it), I get following
> exception in my server.log'. I don't see this exception when I run CMP
> 2.1 tests in same mode. I deploy the ear file, and then execute
> appclient multiple times making sure that tests passes
>
> Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
> object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
> at
> oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
> at
> com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
> at
> pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
>
> Path is as follows:
> appclient-->stateful session-->persistence entities
>
> -stateful session has a method called runPersistenceTest. Please let me
> know how should I code this up,so that test passes after executing just
> client multiple times (cleaning up schema in between runs)
>
> public void runPersistenceTest(){
> CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
> em.persist(c1);
> CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
> em.persist(c2);
> OrderEntity o1=new OrderEntity(100,1);
> em.persist(o1);
> OrderEntity o2=new OrderEntity(101,2);
> em.persist(o2);
> ItemEntity i1=new ItemEntity(100,"Camcorder");
> em.persist(i1);
> List result = em.createQuery("SELECT OBJECT(cust) FROM
> CustomerEntity cust").getResultList();
>



Content-type: message/rfc822

Date: Mon, 31 Oct 2005 15:33:22 -0600
From: Deepa Singh <Deepa.Singh_at_Sun.COM>
Subject: Re: Persistence Test Integrated in QuickLook
To: persistence_at_glassfish.dev.java.net
Cc: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>,
 "Shelly (Donna) McGowan" <Shelly.McGowan_at_Sun.COM>,
 Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>,
 Michael Bouschen <Michael.Bouschen_at_Sun.COM>,
 Sailaja Rao Gangaraju <Sailaja.Rao_at_Sun.COM>
Message-id: <43668DA2.7030307_at_sun.com>
MIME-version: 1.0
Content-type: multipart/alternative;
 boundary="Boundary_(ID_5GbnB6JhF7qUf3GvTiu7FA)"

This is a multi-part message in MIME format.

--Boundary_(ID_5GbnB6JhF7qUf3GvTiu7FA)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Between my first run and second run, I dropped the table and constraints
associated with them, and then re-created the table to make sure
database is in clean condition for successive runs

I looked up spec's Chapter 3 "Entity Operations" to understand "persist"
"detached" state and "flush" operations and still not clear.
I put EntityManager.flush( ) before persist method calls, and still
seeing same behaviour

If I undeploy the application , deploy again and then run the client
after cleaning up database, then there are no exceptions, and PERSIST
operation suceeds.



Marina Vatkina wrote:

>Hi Deepa,
>
>(CC-ing persistence)
>
>Can it be that the record is already there? TopLink code might be
>caching results of a previous run. Keep in mind that CMP code uses
>completely different code for persistence runtime.
>
>thanks,
>-marina
>
>Deepa Singh wrote On 10/31/05 12:52,:
>
>
>>Hi Marina,
>>Persistence Quicklook tests is integrated into GlassFish quicklook test
>>base.
>>glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>>
>>There is only one thing missing, when I run my test (execute only client
>>)twice (after dropping table and re-creating it), I get following
>>exception in my server.log'. I don't see this exception when I run CMP
>>2.1 tests in same mode. I deploy the ear file, and then execute
>>appclient multiple times making sure that tests passes
>>
>>Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
>>object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
>> at
>>oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
>> at
>>oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
>> at
>>com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
>> at
>>pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
>>
>>Path is as follows:
>>appclient-->stateful session-->persistence entities
>>
>>-stateful session has a method called runPersistenceTest. Please let me
>>know how should I code this up,so that test passes after executing just
>>client multiple times (cleaning up schema in between runs)
>>
>> public void runPersistenceTest(){
>> CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
>> em.persist(c1);
>> CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
>> em.persist(c2);
>> OrderEntity o1=new OrderEntity(100,1);
>> em.persist(o1);
>> OrderEntity o2=new OrderEntity(101,2);
>> em.persist(o2);
>> ItemEntity i1=new ItemEntity(100,"Camcorder");
>> em.persist(i1);
>> List result = em.createQuery("SELECT OBJECT(cust) FROM
>>CustomerEntity cust").getResultList();
>>
>>
>>
>
>
>

-- 
Deepa Singh
Sun Java Enterprise System 9.0
J2EE Core
MailStop: USCA14-304
Santa Clara,CA
x40277 +1 408 404 5144
--Boundary_(ID_5GbnB6JhF7qUf3GvTiu7FA)
Content-type: text/html; charset=us-ascii
Content-transfer-encoding: 7BIT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Between my first run and second run, I dropped the table and
constraints associated with them, and then re-created the table to make
sure database is in clean condition for successive runs<br>
<br>
I looked up spec's Chapter 3 "Entity Operations" to understand
"persist" "detached" state and "flush" operations and still not clear.<br>
I put EntityManager.flush( ) before persist method calls, and still
seeing same behaviour<br>
<br>
If I undeploy the application , deploy again and then run the client
after cleaning up database, then there are no exceptions, and PERSIST
operation suceeds.<br>
<br>
<br>
<br>
Marina Vatkina wrote:<br>
<blockquote cite="mid43668754.8010103_at_Sun.COM" type="cite">
  <pre wrap="">Hi Deepa,
(CC-ing persistence)
Can it be that the record is already there? TopLink code might be
caching results of a previous run. Keep in mind that CMP code uses
completely different code for persistence runtime.
thanks,
-marina
Deepa Singh wrote On 10/31/05 12:52,:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi Marina,
Persistence Quicklook tests is integrated into GlassFish quicklook test 
base.
glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
There is only one thing missing, when I run my test (execute only client 
)twice (after dropping table and re-creating  it), I get following 
exception in my server.log'.  I don't see this exception when I run CMP 
2.1 tests in same mode. I deploy the ear file, and then execute 
appclient multiple times making sure that tests passes
Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched 
object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
    at 
oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
    at 
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
    at 
com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
    at 
pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
Path is as follows:
appclient--&gt;stateful session--&gt;persistence entities
-stateful session has a method called runPersistenceTest. Please let me 
know how should I code this up,so that test passes after executing just 
client multiple times (cleaning up schema in between runs)
 public void runPersistenceTest(){
            CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
            em.persist(c1);
            CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
            em.persist(c2);
            OrderEntity o1=new OrderEntity(100,1);
            em.persist(o1);
            OrderEntity o2=new OrderEntity(101,2);
            em.persist(o2);
            ItemEntity i1=new ItemEntity(100,"Camcorder");
            em.persist(i1);
            List result = em.createQuery("SELECT OBJECT(cust) FROM 
CustomerEntity cust").getResultList();
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
Deepa Singh
Sun Java Enterprise System 9.0
J2EE Core
MailStop: USCA14-304
Santa Clara,CA
x40277 +1 408 404 5144</pre>
</body>
</html>
--Boundary_(ID_5GbnB6JhF7qUf3GvTiu7FA)--


Content-type: message/rfc822

Date: Mon, 31 Oct 2005 14:19:10 -0800
From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Subject: Re: Persistence Test Integrated in QuickLook
To: persistence_at_glassfish.dev.java.net
Cc: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>,
 "Shelly (Donna) McGowan" <Shelly.McGowan_at_Sun.COM>,
 Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>,
 Michael Bouschen <Michael.Bouschen_at_Sun.COM>,
 Sailaja Rao Gangaraju <Sailaja.Rao_at_Sun.COM>
Message-id: <4366985E.7090501_at_Sun.COM>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: 7BIT

Deepa,

Deepa Singh wrote On 10/31/05 13:33,:
> Between my first run and second run, I dropped the table and constraints
> associated with them, and then re-created the table to make sure
> database is in clean condition for successive runs

Was the app still up and running while you were in recreating the
tables? If yes, such activities are possible if the persistence
runtime does not use the cached data.

Tom, Gordon,

Is there a way to bypass the cache and always talk to the database
directly?


>
> I looked up spec's Chapter 3 "Entity Operations" to understand "persist"
> "detached" state and "flush" operations and still not clear.

persist operations explicitly says that detached instances
can't be persisted.

> I put EntityManager.flush( ) before persist method calls, and still
> seeing same behaviour

I think your persist() call fails because the backend verifies
if it already knows about this PK for this entity type. As it caches
all data, the instance is found (as detached), and persist fails
right away.

flush() won't change anything.


>
> If I undeploy the application , deploy again and then run the client
> after cleaning up database, then there are no exceptions, and PERSIST
> operation suceeds.

Yes, because now you have a new ClassLoader, and as a result a new
Class for this PK.

thanks,
-marina

>
>
>
> Marina Vatkina wrote:
>
>>Hi Deepa,
>>
>>(CC-ing persistence)
>>
>>Can it be that the record is already there? TopLink code might be
>>caching results of a previous run. Keep in mind that CMP code uses
>>completely different code for persistence runtime.
>>
>>thanks,
>>-marina
>>
>>Deepa Singh wrote On 10/31/05 12:52,:
>>
>>
>>>Hi Marina,
>>>Persistence Quicklook tests is integrated into GlassFish quicklook test
>>>base.
>>>glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>>>
>>>There is only one thing missing, when I run my test (execute only client
>>>)twice (after dropping table and re-creating it), I get following
>>>exception in my server.log'. I don't see this exception when I run CMP
>>>2.1 tests in same mode. I deploy the ear file, and then execute
>>>appclient multiple times making sure that tests passes
>>>
>>>Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
>>>object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
>>> at
>>>oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
>>> at
>>>oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
>>> at
>>>com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
>>> at
>>>pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
>>>
>>>Path is as follows:
>>>appclient-->stateful session-->persistence entities
>>>
>>>-stateful session has a method called runPersistenceTest. Please let me
>>>know how should I code this up,so that test passes after executing just
>>>client multiple times (cleaning up schema in between runs)
>>>
>>> public void runPersistenceTest(){
>>> CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
>>> em.persist(c1);
>>> CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
>>> em.persist(c2);
>>> OrderEntity o1=new OrderEntity(100,1);
>>> em.persist(o1);
>>> OrderEntity o2=new OrderEntity(101,2);
>>> em.persist(o2);
>>> ItemEntity i1=new ItemEntity(100,"Camcorder");
>>> em.persist(i1);
>>> List result = em.createQuery("SELECT OBJECT(cust) FROM
>>>CustomerEntity cust").getResultList();
>>>
>>>
>>>
>>
>>
>>
>
> --
> Deepa Singh
> Sun Java Enterprise System 9.0
> J2EE Core
> MailStop: USCA14-304
> Santa Clara,CA
> x40277 +1 408 404 5144
>



Content-type: message/rfc822

Date: Mon, 31 Oct 2005 16:34:02 -0600
From: Deepa Singh <Deepa.Singh_at_Sun.COM>
Subject: Re: Persistence Test Integrated in QuickLook
To: persistence_at_glassfish.dev.java.net
Cc: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>,
 "Shelly (Donna) McGowan" <Shelly.McGowan_at_Sun.COM>,
 Sanjeeb Kumar Sahoo <Sanjeeb.Sahoo_at_Sun.COM>,
 Michael Bouschen <Michael.Bouschen_at_Sun.COM>,
 Sailaja Rao Gangaraju <Sailaja.Rao_at_Sun.COM>
Message-id: <43669BDA.4000305_at_sun.com>
MIME-version: 1.0
Content-type: text/plain; charset=ISO-8859-1; format=flowed
Content-transfer-encoding: 7BIT



Marina Vatkina wrote:

>Deepa,
>
>Deepa Singh wrote On 10/31/05 13:33,:
>
>
>>Between my first run and second run, I dropped the table and constraints
>>associated with them, and then re-created the table to make sure
>>database is in clean condition for successive runs
>>
>>
>
>Was the app still up and running while you were in recreating the
>tables? If yes, such activities are possible if the persistence
>runtime does not use the cached data.
>
>
Yes. Application was still deployed and enabled while I was recreating
the tables

>Tom, Gordon,
>
>Is there a way to bypass the cache and always talk to the database
>directly?
>
>
>
>
>>I looked up spec's Chapter 3 "Entity Operations" to understand "persist"
>>"detached" state and "flush" operations and still not clear.
>>
>>
>
>persist operations explicitly says that detached instances
>can't be persisted.
>
>
>
>>I put EntityManager.flush( ) before persist method calls, and still
>>seeing same behaviour
>>
>>
>
>I think your persist() call fails because the backend verifies
>if it already knows about this PK for this entity type. As it caches
>all data, the instance is found (as detached), and persist fails
>right away.
>
>flush() won't change anything.
>
>
>
>
>>If I undeploy the application , deploy again and then run the client
>>after cleaning up database, then there are no exceptions, and PERSIST
>>operation suceeds.
>>
>>
>
>Yes, because now you have a new ClassLoader, and as a result a new
>Class for this PK.
>
>thanks,
>-marina
>
>
Thanks for this information. I will put this in README at test level and
enable this test from top level and leave it as it is, until a better
way is found to run the test multiple times without undeploying application

>
>
>>
>>Marina Vatkina wrote:
>>
>>
>>
>>>Hi Deepa,
>>>
>>>(CC-ing persistence)
>>>
>>>Can it be that the record is already there? TopLink code might be
>>>caching results of a previous run. Keep in mind that CMP code uses
>>>completely different code for persistence runtime.
>>>
>>>thanks,
>>>-marina
>>>
>>>Deepa Singh wrote On 10/31/05 12:52,:
>>>
>>>
>>>
>>>
>>>>Hi Marina,
>>>>Persistence Quicklook tests is integrated into GlassFish quicklook test
>>>>base.
>>>>glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>>>>
>>>>There is only one thing missing, when I run my test (execute only client
>>>>)twice (after dropping table and re-creating it), I get following
>>>>exception in my server.log'. I don't see this exception when I run CMP
>>>>2.1 tests in same mode. I deploy the ear file, and then execute
>>>>appclient multiple times making sure that tests passes
>>>>
>>>>Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
>>>>object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
>>>> at
>>>>oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
>>>> at
>>>>oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
>>>> at
>>>>com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
>>>> at
>>>>pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
>>>>
>>>>Path is as follows:
>>>>appclient-->stateful session-->persistence entities
>>>>
>>>>-stateful session has a method called runPersistenceTest. Please let me
>>>>know how should I code this up,so that test passes after executing just
>>>>client multiple times (cleaning up schema in between runs)
>>>>
>>>>public void runPersistenceTest(){
>>>> CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
>>>> em.persist(c1);
>>>> CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
>>>> em.persist(c2);
>>>> OrderEntity o1=new OrderEntity(100,1);
>>>> em.persist(o1);
>>>> OrderEntity o2=new OrderEntity(101,2);
>>>> em.persist(o2);
>>>> ItemEntity i1=new ItemEntity(100,"Camcorder");
>>>> em.persist(i1);
>>>> List result = em.createQuery("SELECT OBJECT(cust) FROM
>>>>CustomerEntity cust").getResultList();
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>--
>>Deepa Singh
>>Sun Java Enterprise System 9.0
>>J2EE Core
>>MailStop: USCA14-304
>>Santa Clara,CA
>>x40277 +1 408 404 5144
>>
>>
>>
>
>
>

-- 
Deepa Singh
Sun Java Enterprise System 9.0
J2EE Core
MailStop: USCA14-304
Santa Clara,CA
x40277 +1 408 404 5144


Content-type: message/rfc822

Date: Tue, 1 Nov 2005 08:17:49 -0500
From: "Gordon Yorke" <gordon.yorke_at_oracle.com>
Subject: RE: Persistence Test Integrated in QuickLook
To: "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>,
 "Deepa Singh" <Deepa.Singh_at_Sun.COM>
Cc: "Mitesh Meswani" <Mitesh.Meswani_at_Sun.COM>,
 "Shelly (Donna) McGowan" <Shelly.McGowan_at_Sun.COM>,
 "Sanjeeb Kumar Sahoo" <Sanjeeb.Sahoo_at_Sun.COM>,
 "Michael Bouschen" <Michael.Bouschen_at_Sun.COM>,
 "Sailaja Rao Gangaraju" <Sailaja.Rao_at_Sun.COM>
Message-id: <20051101081749594.00000002552_at_gyorke-pc2>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: QUOTED-PRINTABLE

Marina,=09
=09TopLink is caching the data internally. Generally users have no i=
ssue with stale data (outside of the standard concurrency issues) but=
 if the end user has processes modifying the data external to TopLink=
 there are configuration options for handling the external updates. =
With the EJB 3.0 specification however there is no clear mechanism fo=
r providing support for configuring TopLink to handle externally modi=
fied data. We are currently evaluating our options and will hopefully=
 have a solution soon.
     In the meantime two options are available. Have the tests clear=
 the objects from the database using the Persistence API or reset the=
 TopLink caches by calling : ((oracle.toplink.essentials.ejb.cmp3.En=
tityManager)entityManager).getActiveSession().initializeAllIdentityMa=
ps().

--Gordon

-----Original Message-----
=46rom: Marina Vatkina [mailto:Marina.Vatkina_at_Sun.COM]
Sent: Monday, October 31, 2005 4:06 PM
To: Deepa Singh
Cc: Mitesh Meswani; Shelly (Donna) McGowan; Sanjeeb Kumar Sahoo; Mich=
ael
Bouschen; Sailaja Rao Gangaraju; persistence
Subject: Re: Persistence Test Integrated in QuickLook


Hi Deepa,

(CC-ing persistence)

Can it be that the record is already there? TopLink code might be
caching results of a previous run. Keep in mind that CMP code uses
completely different code for persistence runtime.

thanks,
-marina

Deepa Singh wrote On 10/31/05 12:52,:
> Hi Marina,
> Persistence Quicklook tests is integrated into GlassFish quicklook =
test
> base.
> glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>
> There is only one thing missing, when I run my test (execute only c=
lient
> )twice (after dropping table and re-creating it), I get following
> exception in my server.log'. I don't see this exception when I run=
 CMP
> 2.1 tests in same mode. I deploy the ear file, and then execute
> appclient multiple times making sure that tests passes
>
> Caused by: java.lang.IllegalArgumentException: Can not PERSIST deta=
tched
> object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f=
0ca71.
> at
> oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObj=
ectForPersist(UnitOfWork.java:3131)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.=
persist(EntityManagerImpl.java:96)
> at
> com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerW=
rapper.java:163)
> at
> pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersiste=
nceTest(StatefulBean.java:25)
>
> Path is as follows:
> appclient-->stateful session-->persistence entities
>
> -stateful session has a method called runPersistenceTest. Please le=
t me
> know how should I code this up,so that test passes after executing =
just
> client multiple times (cleaning up schema in between runs)
>
> public void runPersistenceTest(){
> CustomerEntity c1=3Dnew CustomerEntity(1,"Alice","Santa=
 Clara");
> em.persist(c1);
> CustomerEntity c2=3Dnew CustomerEntity(2,"Betty","Sunny=
vale");
> em.persist(c2);
> OrderEntity o1=3Dnew OrderEntity(100,1);
> em.persist(o1);
> OrderEntity o2=3Dnew OrderEntity(101,2);
> em.persist(o2);
> ItemEntity i1=3Dnew ItemEntity(100,"Camcorder");
> em.persist(i1);
> List result =3D em.createQuery("SELECT OBJECT(cust) FRO=
M
> CustomerEntity cust").getResultList();
>




Content-type: message/rfc822

Date: Tue, 01 Nov 2005 15:43:56 -0600
From: Deepa Singh <Deepa.Singh_at_Sun.COM>
Subject: Re: Persistence Test Integrated in QuickLook
To: persistence_at_glassfish.dev.java.net
Cc: ejb30-tck-team_at_Sun.COM
Message-id: <4367E19C.40707_at_sun.com>
MIME-version: 1.0
Content-type: multipart/alternative;
 boundary="Boundary_(ID_vbLryGd+KVL/P+2Hw3pEDQ)"

This is a multi-part message in MIME format.

--Boundary_(ID_vbLryGd+KVL/P+2Hw3pEDQ)
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi Gordon,
Thanks a lot for clarifying cache issues.
I tried clearing up database through EntityManager.remove() API and now
running into some other issues. Please advice if my usage is incorrect
Test is setup as follows:
Appclient-->SessionBean-->Entities

Session Bean has two separate business methods "runPersistenceTest"
which populate the rows and "cleanUp" which deletes the row after
calling EntityManager.remove()

Populating the row goes on fine, but when I try to remove it, I am now
getting exception,
Caused by: java.lang.IllegalArgumentException: Entity must be managed to
call remove: ID: 2: name :Betty: city :Sunnyvale, try merging the
detatched and try the remove again.
    at
oracle.toplink.essentials.publicinterface.UnitOfWork.performRemove(UnitOfWork.java:2692)
    at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.remove(EntityManagerImpl.java:117)
    at
com.sun.enterprise.util.EntityManagerWrapper.remove(EntityManagerWrapper.java:171)

    at
pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.cleanUp(StatefulBean.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)

Just to be extra sure, I am now calling EntityManager.merge () and then
check if entity is in managed state by calling "contains". "contains"
returns FALSE, and if I still call "remove" then I get above mentioned
exception. I have specified a VERSION column as well for all three
entities , and test is run on Derby datatabase All transaction
attributes on session bean's business methods are Defaults which is
"REQUIRED"

If cleanUp () is called inside runPersistenceTest , then I am able to
call entities.remove successfully. But if it is invoked as a separate
business method from application client, then even after calling merge,
entity is in detached state.



Gordon Yorke wrote:

>Marina,
> TopLink is caching the data internally. Generally users have no issue with stale data (outside of the standard concurrency issues) but if the end user has processes modifying the data external to TopLink there are configuration options for handling the external updates. With the EJB 3.0 specification however there is no clear mechanism for providing support for configuring TopLink to handle externally modified data. We are currently evaluating our options and will hopefully have a solution soon.
> In the meantime two options are available. Have the tests clear the objects from the database using the Persistence API or reset the TopLink caches by calling : ((oracle.toplink.essentials.ejb.cmp3.EntityManager)entityManager).getActiveSession().initializeAllIdentityMaps().
>
>--Gordon
>
>-----Original Message-----
>From: Marina Vatkina [mailto:Marina.Vatkina_at_Sun.COM]
>Sent: Monday, October 31, 2005 4:06 PM
>To: Deepa Singh
>Cc: Mitesh Meswani; Shelly (Donna) McGowan; Sanjeeb Kumar Sahoo; Michael
>Bouschen; Sailaja Rao Gangaraju; persistence
>Subject: Re: Persistence Test Integrated in QuickLook
>
>
>Hi Deepa,
>
>(CC-ing persistence)
>
>Can it be that the record is already there? TopLink code might be
>caching results of a previous run. Keep in mind that CMP code uses
>completely different code for persistence runtime.
>
>thanks,
>-marina
>
>Deepa Singh wrote On 10/31/05 12:52,:
>
>
>>Hi Marina,
>>Persistence Quicklook tests is integrated into GlassFish quicklook test
>>base.
>>glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>>
>>There is only one thing missing, when I run my test (execute only client
>>)twice (after dropping table and re-creating it), I get following
>>exception in my server.log'. I don't see this exception when I run CMP
>>2.1 tests in same mode. I deploy the ear file, and then execute
>>appclient multiple times making sure that tests passes
>>
>>Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
>>object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
>> at
>>oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
>> at
>>oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
>> at
>>com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
>> at
>>pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
>>
>>Path is as follows:
>>appclient-->stateful session-->persistence entities
>>
>>-stateful session has a method called runPersistenceTest. Please let me
>>know how should I code this up,so that test passes after executing just
>>client multiple times (cleaning up schema in between runs)
>>
>> public void runPersistenceTest(){
>> CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
>> em.persist(c1);
>> CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
>> em.persist(c2);
>> OrderEntity o1=new OrderEntity(100,1);
>> em.persist(o1);
>> OrderEntity o2=new OrderEntity(101,2);
>> em.persist(o2);
>> ItemEntity i1=new ItemEntity(100,"Camcorder");
>> em.persist(i1);
>> List result = em.createQuery("SELECT OBJECT(cust) FROM
>>CustomerEntity cust").getResultList();
>>
>>
>>
>
>
>
>

-- 
Deepa Singh
Sun Java Enterprise System 9.0
J2EE Core
MailStop: USCA14-304
Santa Clara,CA
x40277 +1 408 404 5144
--Boundary_(ID_vbLryGd+KVL/P+2Hw3pEDQ)
Content-type: text/html; charset=us-ascii
Content-transfer-encoding: 7BIT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Gordon,<br>
Thanks a lot for clarifying cache issues.<br>
I tried clearing up database through EntityManager.remove() API and now
running into some other issues. Please advice if my usage is incorrect<br>
Test is setup as follows:<br>
Appclient--&gt;SessionBean--&gt;Entities<br>
<br>
Session Bean has two separate business methods "runPersistenceTest"
which populate the rows and "cleanUp" which deletes the row after
calling EntityManager.remove()<br>
<br>
Populating the row goes on fine, but when I try to remove it,&nbsp; I am now
getting exception,<br>
Caused by: java.lang.IllegalArgumentException: Entity must be managed
to call remove: ID: 2: name :Betty: city :Sunnyvale, try merging the
detatched and try the remove again.<br>
&nbsp;&nbsp;&nbsp; at
oracle.toplink.essentials.publicinterface.UnitOfWork.performRemove(UnitOfWork.java:2692)<br>
&nbsp;&nbsp;&nbsp; at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.remove(EntityManagerImpl.java:117)<br>
&nbsp;&nbsp;&nbsp; at
com.sun.enterprise.util.EntityManagerWrapper.remove(EntityManagerWrapper.java:171)<br>
<br>
&nbsp;&nbsp;&nbsp; at
pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.cleanUp(StatefulBean.java:51)<br>
&nbsp;&nbsp;&nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
&nbsp;&nbsp;&nbsp; at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
&nbsp;&nbsp;&nbsp; at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
<br>
Just to be extra sure, I am now calling EntityManager.merge () and then
check if entity is in managed state by calling "contains". "contains"
returns FALSE, and if I still call "remove" then I get above mentioned
exception. I have specified a VERSION column as well for all three
entities , and test is run on Derby datatabase All transaction
attributes on session bean's business methods are Defaults which is
"REQUIRED"<br>
<br>
If cleanUp () is called inside runPersistenceTest , then I am able to
call entities.remove successfully. But if it is invoked as a separate
business method from application client, then even after calling merge,
entity is in detached state.<br>
<br>
<br>
<br>
Gordon Yorke wrote:<br>
<blockquote cite="mid20051101081749594.00000002552_at_gyorke-pc2"
 type="cite">
  <pre wrap="">Marina,	
	TopLink is caching the data internally.  Generally users have no issue with stale data (outside of the standard concurrency issues) but if the end user has processes modifying the data external to TopLink there are configuration options for handling the external updates.  With the EJB 3.0 specification however there is no clear mechanism for providing support for configuring TopLink to handle externally modified data. We are currently evaluating our options and will hopefully have a solution soon.
     In the meantime two options are available.  Have the tests clear the objects from the database using the Persistence API or reset the TopLink caches by calling :  ((oracle.toplink.essentials.ejb.cmp3.EntityManager)entityManager).getActiveSession().initializeAllIdentityMaps().
--Gordon
-----Original Message-----
From: Marina Vatkina [<a class="moz-txt-link-freetext" href="mailto:Marina.Vatkina_at_Sun.COM">mailto:Marina.Vatkina_at_Sun.COM</a>]
Sent: Monday, October 31, 2005 4:06 PM
To: Deepa Singh
Cc: Mitesh Meswani; Shelly (Donna) McGowan; Sanjeeb Kumar Sahoo; Michael
Bouschen; Sailaja Rao Gangaraju; persistence
Subject: Re: Persistence Test Integrated in QuickLook
Hi Deepa,
(CC-ing persistence)
Can it be that the record is already there? TopLink code might be
caching results of a previous run. Keep in mind that CMP code uses
completely different code for persistence runtime.
thanks,
-marina
Deepa Singh wrote On 10/31/05 12:52,:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi Marina,
Persistence Quicklook tests is integrated into GlassFish quicklook test
base.
glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
There is only one thing missing, when I run my test (execute only client
)twice (after dropping table and re-creating  it), I get following
exception in my server.log'.  I don't see this exception when I run CMP
2.1 tests in same mode. I deploy the ear file, and then execute
appclient multiple times making sure that tests passes
Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
    at
oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
    at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
    at
com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
    at
pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
Path is as follows:
appclient--&gt;stateful session--&gt;persistence entities
-stateful session has a method called runPersistenceTest. Please let me
know how should I code this up,so that test passes after executing just
client multiple times (cleaning up schema in between runs)
 public void runPersistenceTest(){
            CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
            em.persist(c1);
            CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
            em.persist(c2);
            OrderEntity o1=new OrderEntity(100,1);
            em.persist(o1);
            OrderEntity o2=new OrderEntity(101,2);
            em.persist(o2);
            ItemEntity i1=new ItemEntity(100,"Camcorder");
            em.persist(i1);
            List result = em.createQuery("SELECT OBJECT(cust) FROM
CustomerEntity cust").getResultList();
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
Deepa Singh
Sun Java Enterprise System 9.0
J2EE Core
MailStop: USCA14-304
Santa Clara,CA
x40277 +1 408 404 5144</pre>
</body>
</html>
--Boundary_(ID_vbLryGd+KVL/P+2Hw3pEDQ)--


Content-type: message/rfc822

Date: Tue, 01 Nov 2005 14:42:13 -0800
From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Subject: Re: Persistence Test Integrated in QuickLook
To: persistence_at_glassfish.dev.java.net
Cc: ejb30-tck-team_at_Sun.COM
Message-id: <4367EF45.A0C98D91_at_sun.COM>
MIME-version: 1.0
Content-type: multipart/alternative;
 boundary="Boundary_(ID_a4kiAgNlLIZ/D/Qrg7lmfA)"


--Boundary_(ID_a4kiAgNlLIZ/D/Qrg7lmfA)
Content-type: text/plain; charset=iso-8859-15
Content-transfer-encoding: 7BIT

Hi Deepa,

When extended PersistenceContext is fully supported (Gordon, what's the
status on this?) you should be able to use Statefull SB to run 2 operations
with the same EM.

You can either do em.merge(o); em.remove(o); or o = em.find(...); em.remove(o);
If either of them is not working, it's a bug :)

thanks,
-marina

Deepa Singh wrote:

> Hi Gordon,
> Thanks a lot for clarifying cache issues.
> I tried clearing up database through EntityManager.remove() API and now
> running into some other issues. Please advice if my usage is incorrect
> Test is setup as follows:
> Appclient-->SessionBean-->Entities
>
> Session Bean has two separate business methods "runPersistenceTest" which
> populate the rows and "cleanUp" which deletes the row after calling
> EntityManager.remove()
>
> Populating the row goes on fine, but when I try to remove it, I am now
> getting exception,
> Caused by: java.lang.IllegalArgumentException: Entity must be managed to call
> remove: ID: 2: name :Betty: city :Sunnyvale, try merging the detatched and try
> the remove again.
> at
> oracle.toplink.essentials.publicinterface.UnitOfWork.performRemove(UnitOfWork.java:2692)
>
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.remove(EntityManagerImpl.java:117)
>
> at
> com.sun.enterprise.util.EntityManagerWrapper.remove(EntityManagerWrapper.java:171)
>
> at
> pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.cleanUp(StatefulBean.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)
>
> Just to be extra sure, I am now calling EntityManager.merge () and then check
> if entity is in managed state by calling "contains". "contains" returns FALSE,
> and if I still call "remove" then I get above mentioned exception. I have
> specified a VERSION column as well for all three entities , and test is run on
> Derby datatabase All transaction attributes on session bean's business methods
> are Defaults which is "REQUIRED"
>
> If cleanUp () is called inside runPersistenceTest , then I am able to call
> entities.remove successfully. But if it is invoked as a separate business
> method from application client, then even after calling merge, entity is in
> detached state.
>
>
>
> Gordon Yorke wrote:
>
>> Marina,
>> TopLink is caching the data internally. Generally users have no
>> issue with stale data (outside of the standard concurrency issues) but if
>> the end user has processes modifying the data external to TopLink there are
>> configuration options for handling the external updates. With the EJB 3.0
>> specification however there is no clear mechanism for providing support for
>> configuring TopLink to handle externally modified data. We are currently
>> evaluating our options and will hopefully have a solution soon.
>> In the meantime two options are available. Have the tests clear the
>> objects from the database using the Persistence API or reset the TopLink
>> caches by calling :
>> ((oracle.toplink.essentials.ejb.cmp3.EntityManager)entityManager).getActiveSession().initializeAllIdentityMaps().
>>
>> --Gordon
>>
>> -----Original Message-----
>> From: Marina Vatkina [mailto:Marina.Vatkina_at_Sun.COM]
>> Sent: Monday, October 31, 2005 4:06 PM
>> To: Deepa Singh
>> Cc: Mitesh Meswani; Shelly (Donna) McGowan; Sanjeeb Kumar Sahoo; Michael
>> Bouschen; Sailaja Rao Gangaraju; persistence
>> Subject: Re: Persistence Test Integrated in QuickLook
>>
>>
>> Hi Deepa,
>>
>> (CC-ing persistence)
>>
>> Can it be that the record is already there? TopLink code might be
>> caching results of a previous run. Keep in mind that CMP code uses
>> completely different code for persistence runtime.
>>
>> thanks,
>> -marina
>>
>> Deepa Singh wrote On 10/31/05 12:52,:
>>
>> > Hi Marina,
>> > Persistence Quicklook tests is integrated into GlassFish quicklook test
>> > base.
>> > glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany
>> >
>> > There is only one thing missing, when I run my test (execute only client
>> > )twice (after dropping table and re-creating it), I get following
>> > exception in my server.log'. I don't see this exception when I run CMP
>> > 2.1 tests in same mode. I deploy the ear file, and then execute
>> > appclient multiple times making sure that tests passes
>> >
>> > Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
>> > object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
>> > at
>> > oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
>> > at
>> > oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
>> > at
>> > com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
>> > at
>> > pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)
>> >
>> > Path is as follows:
>> > appclient-->stateful session-->persistence entities
>> >
>> > -stateful session has a method called runPersistenceTest. Please let me
>> > know how should I code this up,so that test passes after executing just
>> > client multiple times (cleaning up schema in between runs)
>> >
>> > public void runPersistenceTest(){
>> > CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
>> > em.persist(c1);
>> > CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
>> > em.persist(c2);
>> > OrderEntity o1=new OrderEntity(100,1);
>> > em.persist(o1);
>> > OrderEntity o2=new OrderEntity(101,2);
>> > em.persist(o2);
>> > ItemEntity i1=new ItemEntity(100,"Camcorder");
>> > em.persist(i1);
>> > List result = em.createQuery("SELECT OBJECT(cust) FROM
>> > CustomerEntity cust").getResultList();
>> >
>> >
>>
>>
> --
> Deepa Singh
> Sun Java Enterprise System 9.0
> J2EE Core
> MailStop: USCA14-304
> Santa Clara,CA
> x40277 +1 408 404 5144
>

--Boundary_(ID_a4kiAgNlLIZ/D/Qrg7lmfA)
Content-type: text/html; charset=iso-8859-15
Content-transfer-encoding: 7BIT

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body text="#000000" bgcolor="#FFFFFF">
Hi Deepa,
<p>When extended PersistenceContext is fully supported (Gordon, what's
the
<br>status on this?) you should be able to use Statefull SB&nbsp;to run
2 operations
<br>with the same EM.
<p>You can either do em.merge(o); em.remove(o); or o = em.find(...); em.remove(o);
<br>If either of them is not working, it's a bug :)
<p>thanks,
<br>-marina
<p>Deepa Singh wrote:
<blockquote TYPE=CITE>Hi Gordon,
<br>Thanks a lot for clarifying cache issues.
<br>I tried clearing up database through EntityManager.remove() API and
now running into some other issues. Please advice if my usage is incorrect
<br>Test is setup as follows:
<br>Appclient-->SessionBean-->Entities
<p>Session Bean has two separate business methods "runPersistenceTest"
which populate the rows and "cleanUp" which deletes the row after calling
EntityManager.remove()
<p>Populating the row goes on fine, but when I try to remove it,&nbsp;
I am now getting exception,
<br>Caused by: java.lang.IllegalArgumentException: Entity must be managed
to call remove: ID: 2: name :Betty: city :Sunnyvale, try merging the detatched
and try the remove again.
<br>&nbsp;&nbsp;&nbsp; at oracle.toplink.essentials.publicinterface.UnitOfWork.performRemove(UnitOfWork.java:2692)
<br>&nbsp;&nbsp;&nbsp; at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.remove(EntityManagerImpl.java:117)
<br>&nbsp;&nbsp;&nbsp; at com.sun.enterprise.util.EntityManagerWrapper.remove(EntityManagerWrapper.java:171)
<p>&nbsp;&nbsp;&nbsp; at pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.cleanUp(StatefulBean.java:51)
<br>&nbsp;&nbsp;&nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
<br>&nbsp;&nbsp;&nbsp; at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
<br>&nbsp;&nbsp;&nbsp; at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
<p>Just to be extra sure, I am now calling EntityManager.merge () and then
check if entity is in managed state by calling "contains". "contains" returns
FALSE, and if I still call "remove" then I get above mentioned exception.
I have specified a VERSION column as well for all three entities , and
test is run on Derby datatabase All transaction attributes on session bean's
business methods are Defaults which is "REQUIRED"
<p>If cleanUp () is called inside runPersistenceTest , then I am able to
call entities.remove successfully. But if it is invoked as a separate business
method from application client, then even after calling merge, entity is
in detached state.
<br>&nbsp;
<br>&nbsp;
<p>Gordon Yorke wrote:
<blockquote cite="mid20051101081749594.00000002552_at_gyorke-pc2"
 type="cite">
<pre wrap="">Marina,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TopLink is caching the data internally.&nbsp; Generally users have no issue with stale data (outside of the standard concurrency issues) but if the end user has processes modifying the data external to TopLink there are configuration options for handling the external updates.&nbsp; With the EJB 3.0 specification however there is no clear mechanism for providing support for configuring TopLink to handle externally modified data. We are currently evaluating our options and will hopefully have a solution soon.
&nbsp;&nbsp;&nbsp;&nbsp; In the meantime two options are available.&nbsp; Have the tests clear the objects from the database using the Persistence API or reset the TopLink caches by calling :&nbsp; ((oracle.toplink.essentials.ejb.cmp3.EntityManager)entityManager).getActiveSession().initializeAllIdentityMaps().

--Gordon

-----Original Message-----
From: Marina Vatkina [<a href="mailto:Marina.Vatkina_at_Sun.COM" class="moz-txt-link-freetext">mailto:Marina.Vatkina_at_Sun.COM</a>]
Sent: Monday, October 31, 2005 4:06 PM
To: Deepa Singh
Cc: Mitesh Meswani; Shelly (Donna) McGowan; Sanjeeb Kumar Sahoo; Michael
Bouschen; Sailaja Rao Gangaraju; persistence
Subject: Re: Persistence Test Integrated in QuickLook


Hi Deepa,

(CC-ing persistence)

Can it be that the record is already there? TopLink code might be
caching results of a previous run. Keep in mind that CMP code uses
completely different code for persistence runtime.

thanks,
-marina

Deepa Singh wrote On 10/31/05 12:52,:
</pre>

<blockquote type="cite">
<pre wrap="">Hi Marina,
Persistence Quicklook tests is integrated into GlassFish quicklook test
base.
glassfish/appserv-tests/sqetests/ejb/ejb30/persistence/onetomany

There is only one thing missing, when I run my test (execute only client
)twice (after dropping table and re-creating&nbsp; it), I get following
exception in my server.log'.&nbsp; I don't see this exception when I run CMP
2.1 tests in same mode. I deploy the ear file, and then execute
appclient multiple times making sure that tests passes

Caused by: java.lang.IllegalArgumentException: Can not PERSIST detatched
object: pe.ejb.ejb30.persistence.toplinksample.ejb.CustomerEntity_at_f0ca71.
&nbsp;&nbsp;&nbsp; at
oracle.toplink.essentials.publicinterface.UnitOfWork.registerNewObjectForPersist(UnitOfWork.java:3131)
&nbsp;&nbsp;&nbsp; at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:96)
&nbsp;&nbsp;&nbsp; at
com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:163)
&nbsp;&nbsp;&nbsp; at
pe.ejb.ejb30.persistence.toplinksample.ejb.StatefulBean.runPersistenceTest(StatefulBean.java:25)

Path is as follows:
appclient-->stateful session-->persistence entities

-stateful session has a method called runPersistenceTest. Please let me
know how should I code this up,so that test passes after executing just
client multiple times (cleaning up schema in between runs)

&nbsp;public void runPersistenceTest(){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomerEntity c1=new CustomerEntity(1,"Alice","Santa Clara");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; em.persist(c1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomerEntity c2=new CustomerEntity(2,"Betty","Sunnyvale");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; em.persist(c2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OrderEntity o1=new OrderEntity(100,1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; em.persist(o1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OrderEntity o2=new OrderEntity(101,2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; em.persist(o2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ItemEntity i1=new ItemEntity(100,"Camcorder");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; em.persist(i1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List result = em.createQuery("SELECT OBJECT(cust) FROM
CustomerEntity cust").getResultList();

</pre>
</blockquote>

<pre wrap=""><!---->

</pre>
</blockquote>

<pre class="moz-signature" cols="72">--&nbsp;
Deepa Singh
Sun Java Enterprise System 9.0
J2EE Core
MailStop: USCA14-304
Santa Clara,CA
x40277 +1 408 404 5144</pre>
</blockquote>

</body>
</html>

--Boundary_(ID_a4kiAgNlLIZ/D/Qrg7lmfA)--


Content-type: message/rfc822

Date: Tue, 01 Nov 2005 14:49:55 +0100
From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Subject: Re: Question about EJBQL HAVING clause
To: Mike Keith <michael.keith_at_oracle.com>
Cc: Linda DeMichiel <Linda.Demichiel_at_Sun.COM>,
 "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>
Message-id: <43677283.5040708_at_sun.com>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi Mike,

> Hi Michael,
>
> 1) I never felt the need for HAVING clauses to support aggregates,
> but the case that you brought up seems reasonable. We'll look
> into it and see what the issues with supporting it are. Perhaps
> we can talk about it offline on Monday.

AFAIK, support for aggregates in the HAVING clause is standard SQL, so I
would not expect any issues.

>
> 2) I have always considered the HAVING to be part of a GROUP BY.
> I think the grammar should disallow the case where it is not.

 From my perspective support for HAVING w/o GROUP BY does not add much
value, so I agree that the grammar should disallow it.

>
> We will check with the group on both of these issues.

Thanks!

Regards Michael

>
> Thanks,
> -Mike
>
>
>>-----Original Message-----
>>From: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
>>Sent: Tuesday, October 25, 2005 8:45 AM
>>To: Linda DeMichiel; Mike Keith
>>Cc: persistence_at_glassfish.dev.java.net
>>Subject: Question about EJBQL HAVING clause
>>
>>
>>Hi Linda, hi Mike,
>>
>>I have two questions about the HAVING clause in EJBQL.
>>
>>(1) Aggregates in HAVING clause
>>I read the current EJBQL BNF that is does not allow aggregates in the
>>HAVING clause. I'm wondering whether this is on purpose, because the
>>following query would not be valid:
>> SELECT c.country, COUNT(c) FROM Customer c
>> GROUP by c.country HAVING COUNT(c.country) > 3
>>
>>The BNF for the HAVING clause is (see section 4.7 GROUP BY, HAVING on
>>page 79 and the BNF on page 92):
>> having_clause ::= HAVING conditional_expression
>>Only select_expression, simple_select_expression and constructor_item
>>allow aggregates and none of them is reachable from
>>conditional_expression.
>>
>>(2) HAVING clause w/o GROUP BY clause
>>
>>The spec explicitly allows a HAVING query w/o GROUP BY. Are there any
>>SELECT clause restrictions in this case?
>>
>>I have the feeling that there are issues with mapping such queries to
>>SQL. I tried to run SQL HAVING queries w/o GROUP BY on Oracle
>>and Derby,
>>but did not have success. Oracle returns an error message "ORA-00979:
>>not a GROUP BY expression". MySql seems to accept HAVING w/o GROUP BY,
>>but only if the SELECT clause only uses columns from the
>>HAVING clause.
>>
>>Thanks.
>>
>>Regards Michael
>>
>
>



Content-type: message/rfc822

Date: Tue, 01 Nov 2005 14:56:48 +0100
From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Subject: Re: Question about EJBQL HAVING clause
To: Linda.Demichiel_at_Sun.COM
Cc: Mike Keith <michael.keith_at_oracle.com>, persistence_at_glassfish.dev.java.net
Message-id: <43677420.3040708_at_sun.com>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi Linda,

> Hi Michael,
>
>
> Michael Bouschen wrote:
>
>> Hi Linda, hi Mike,
>>
>> I have two questions about the HAVING clause in EJBQL.
>>
>> (1) Aggregates in HAVING clause
>> I read the current EJBQL BNF that is does not allow aggregates in the
>> HAVING clause. I'm wondering whether this is on purpose, because the
>> following query would not be valid:
>> SELECT c.country, COUNT(c) FROM Customer c
>> GROUP by c.country HAVING COUNT(c.country) > 3
>>
>> The BNF for the HAVING clause is (see section 4.7 GROUP BY, HAVING on
>> page 79 and the BNF on page 92):
>> having_clause ::= HAVING conditional_expression
>> Only select_expression, simple_select_expression and constructor_item
>> allow aggregates and none of them is reachable from
>> conditional_expression.
>>
>
> This is a bug.
>
> The HAVING clause must specify search conditions over the grouping
> columns or aggregate functions that apply to grouping columns.

An option for the BNF is adding aggregates to the non-terminal
arithmetic_primary with a footnote saying that it is only allowed as
part of the having clause expression.

>
>
>> (2) HAVING clause w/o GROUP BY clause
>>
>> The spec explicitly allows a HAVING query w/o GROUP BY. Are there any
>> SELECT clause restrictions in this case?
>>
>
> When HAVING is used in SQL without GROUP BY, the entire table is
> treated as a single group, and the select list can only
> consist of aggregate functions (and literals, which EJB QL doesn't
> currently specify for use in the SELECT clause).

Should the spec explicitly spell out the restrictions for the SELECT
clause in case there is a HAVING w/o GROUP BY?

However, I'm not sure whether HAVING w/o GROUP BY adds much value and
I'm a little concerned about some SQL databases not supporting this.

Thanks.

Regards Michael

>
>
>> I have the feeling that there are issues with mapping such queries to
>> SQL. I tried to run SQL HAVING queries w/o GROUP BY on Oracle and
>> Derby, but did not have success. Oracle returns an error message
>> "ORA-00979: not a GROUP BY expression". MySql seems to accept HAVING
>> w/o GROUP BY, but only if the SELECT clause only uses columns from the
>> HAVING clause.
>>
>> Thanks.
>>
>
> Thank you!
>
> -Linda
>
>
>> Regards Michael



Content-type: message/rfc822

Date: Tue, 01 Nov 2005 15:15:40 +0100
From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Subject: Question about EJBQL queries with multiple expressions in the SELECT
 clause
To: Linda DeMichiel <Linda.Demichiel_at_Sun.COM>,
 Mike Keith <michael.keith_at_oracle.com>
Cc: "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>
Message-id: <4367788C.5050009_at_sun.com>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi Linda, hi Mike,

with EJB3 an EJBQL query might have multiple expressions in the SELECT
clause, e.g. "SELECT e.firstname, e.lastname FROM Employee e". What is
the return type in this case? More specific, what is the type of the
elements in the list returned by getResultList resp. what is the type of
the instance returned by getSingleResult? Did I overlook something in
the spec?

I think it is important for the user to know what to expect when
iterating the query result, it might be an object array, a list, etc.

Thanks!

Regards Michael


Content-type: message/rfc822

Date: Tue, 01 Nov 2005 17:33:40 +0100
From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Subject: Re: Multiple Return types EJBQL
To: Gordon Yorke <gordon.yorke_at_oracle.com>
Cc: tlcore_ca <tlcore_ca_at_oracle.com>,
 "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>
Message-id: <436798E4.3000606_at_sun.com>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii; format=flowed
Content-transfer-encoding: 7BIT

Hi Gordon,

thanks for the info.

Yes, I saw your checkin and started looking into adding support for
EJBQL queries with multiple expressions in the SELECT clause. The
example setup code helps (e.g. I was not aware of method
returnWithoutReportQueryResult).

However, I still have some questions and hope you can help:

(1) Both examples use a ReportQuery. The current EJBQL code creates an
ReadAllQuery if the SELECT clause uses an identification variable
"SELECT c FROM Customer c". In all other cases it creates a ReportQuery.
Is there any specific reason to create a ReadAllQuery (and not a
ReportQuery) for the above EJBQL? It would be easier if we could always
create a ReportQuery for an EJBQL SELECT query.

(2) What is the reference class in case of multiple expressions
selecting values from different classes? E.g.
   SELECT c.name, o.totalPrice FROM Order o JOIN o.customer c
And what is it if one of the expression selects an association field?
   SELECT o.customer, o.orderId, o.totalPrice FROM Order o

Regards Michael


> Hello Michael,
> I'm not sure how Tom generally organises these feature notifications but i have compeleted (and checked into CVS) the work required to return multiple return types in a single EJBQL query (ie Select o.customer, o.id, FROM Order o where o.customer.name='Somename')
>
> To support this type of selection a TopLink ReportQuery should be used. Each of the selection items (ie o.customer) can be added as an attribute. So as an example the setup code for the above EJBQL would be:
>
> ReportQuery reportQuery = new ReportQuery();
> reportQuery.returnWithoutReportQueryResult();
> reportQuery.setReferenceClass(Order.class);
> ExpressionBuilder orderBuilder = reportQuery.getExpressionBuilder();
> reportQuery.addAttribute("someString-a",empbuilder.get("customer"));
> reportQuery.addAttribute("someString-b",empbuilder.get("id"));
> reportQuery.setSelectionCriteria(empbuilder.get("customer").get("name").equal("Somename");
>
>
>
> Selecting a base object for a query like SELECT c FROM Customer c can be completed as follows:
>
> ReportQuery reportQuery = new ReportQuery();
> reportQuery.returnWithoutReportQueryResult();
> reportQuery.setReferenceClass(Customer.class);
> ExpressionBuilder customerBuilder = reportQuery.getExpressionBuilder();
> reportQuery.addAttribute("someString-a", empbuilder);
>
> This is not quite straight forward so if you have any questions please feel free to ask.
> --Gordon
> __
> Gordon Yorke
> Senior Software Engineer
> TopLink
> Oracle Canada
> <http://www.oracle.com/>
> Main: (613) 783-4585
> Email: gordon.yorke_at_oracle.com
>
>



Content-type: message/rfc822

Date: Tue, 1 Nov 2005 16:14:28 -0500
From: "Gordon Yorke" <gordon.yorke_at_oracle.com>
Subject: RE: Multiple Return types EJBQL
To: "Michael Bouschen" <Michael.Bouschen_at_Sun.COM>
Cc: tlcore_ca <tlcore_ca_at_oracle.com>,
 "persistence_at_glassfish.dev.java.net" <persistence_at_glassfish.dev.java.net>
Message-id: <20051101161428578.00000002552_at_gyorke-pc2>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii
Content-transfer-encoding: QUOTED-PRINTABLE

Hello Michael,
=09There are two reasons for our use of ReadAllQuery. The first and =
most important is caching. By using the ReadAllQuery we can cache re=
sults, even avoid certain queries for selectSingleResult. The second=
 is that until the code I checked in was finished the ReportQuery cou=
ld not return entities. It would be preferable if the ReadAllQuery c=
ould continue to be built except in cases where a ReportQuery is requ=
ired.

=09You can use the class of the first entity class in the FROM clause=
. The reference class is used as the base for the expressions used b=
y the query. The query's ExpressionBuilder will have the class type =
set in the query.
I am not being the clearest here so if you have any more questions pl=
ease feel free to ask. I will try to expand my answers.
--Gordon

-----Original Message-----
=46rom: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
Sent: Tuesday, November 01, 2005 11:34 AM
To: Gordon Yorke
Cc: tlcore_ca; persistence_at_glassfish.dev.java.net
Subject: Re: Multiple Return types EJBQL


Hi Gordon,

thanks for the info.

Yes, I saw your checkin and started looking into adding support for
EJBQL queries with multiple expressions in the SELECT clause. The
example setup code helps (e.g. I was not aware of method
returnWithoutReportQueryResult).

However, I still have some questions and hope you can help:

(1) Both examples use a ReportQuery. The current EJBQL code creates a=
n
ReadAllQuery if the SELECT clause uses an identification variable
"SELECT c FROM Customer c". In all other cases it creates a ReportQue=
ry.
Is there any specific reason to create a ReadAllQuery (and not a
ReportQuery) for the above EJBQL? It would be easier if we could alwa=
ys
create a ReportQuery for an EJBQL SELECT query.

(2) What is the reference class in case of multiple expressions
selecting values from different classes? E.g.
   SELECT c.name, o.totalPrice FROM Order o JOIN o.customer c
And what is it if one of the expression selects an association field?
   SELECT o.customer, o.orderId, o.totalPrice FROM Order o

Regards Michael


> Hello Michael,
> =09I'm not sure how Tom generally organises these feature notificat=
ions but i have compeleted (and checked into CVS) the work required t=
o return multiple return types in a single EJBQL query (ie Select o.c=
ustomer, o.id, FROM Order o where o.customer.name=3D'Somename')
>
> =09To support this type of selection a TopLink ReportQuery should b=
e used. Each of the selection items (ie o.customer) can be added as =
an attribute. So as an example the setup code for the above EJBQL wo=
uld be:
>
> ReportQuery reportQuery =3D new ReportQuery();
> reportQuery.returnWithoutReportQueryResult();
> reportQuery.setReferenceClass(Order.class);
> ExpressionBuilder orderBuilder =3D reportQuery.getExpressio=
nBuilder();
> reportQuery.addAttribute("someString-a",empbuilder.get("cus=
tomer"));
> reportQuery.addAttribute("someString-b",empbuilder.get("id"=
));
> reportQuery.setSelectionCriteria(empbuilder.get("customer")=
.get("name").equal("Somename");
>
>
>
> Selecting a base object for a query like SELECT c FROM Customer c c=
an be completed as follows:
>
> ReportQuery reportQuery =3D new ReportQuery();
> reportQuery.returnWithoutReportQueryResult();
> reportQuery.setReferenceClass(Customer.class);
> ExpressionBuilder customerBuilder =3D reportQuery.getExpres=
sionBuilder();
> reportQuery.addAttribute("someString-a", empbuilder);
>
> This is not quite straight forward so if you have any questions ple=
ase feel free to ask.
> --Gordon
> __
> Gordon Yorke
> Senior Software Engineer
> TopLink
> Oracle Canada
> <http://www.oracle.com/>
> Main: (613) 783-4585
> Email: gordon.yorke_at_oracle.com
>
>