Issue Details (XML | Word | Printable)

Key: SAMPLES-1
Type: Bug Bug
Status: Resolved Resolved
Resolution: Won't Fix
Priority: Major Major
Assignee: Unassigned
Reporter: David G. Friedman
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Samples

JPA tutorial 1.2.0 generates incorrect query

Created: 27/Mar/08 11:04 PM   Updated: 16/Aug/12 02:56 PM   Resolved: 16/Aug/12 02:56 PM
Component/s: None
Affects Version/s: 3.1
Fix Version/s: None

Environment: Linux Ant JDK 1.6.0_04-b12

Forum Thread URL: http://www.jpox.org/servlet/forum/viewthread?thread=4973
Datastore: Apache Derby, HSQL, PostgreSQL
Severity: Production


 Description  « Hide
Running the standard jpa tutorial 1.2.0 src zip does not run as documented on the site at: http://www.jpox.org/docs/guides/jpa/tutorial.html The real output from the sample jpa tutorial does not return the book as it should:

[schematool] SchemaTool completed successfully

runtutorial:
     [java] JPOX Tutorial with JPA
     [java] ======================
     [java] Persisting products
     [java] Product and Book have been persisted
     [java]
     [java] Executing Query for Products with price below 150.00
     [java]
     [java] Deleting all products from persistence
     [java]
     [java] End of Tutorial

BUILD SUCCESSFUL

The problem is the query generated by JPOX for the org.jpox.samples.tutorial.jpa.Main.java class. The logs show a query which will not return the $49.99 book entry as suggested in the site documentation. Because I only know simple SQL, not union/join statements, I cannot suggest where the query generation went wrong. Here is the query DEBUG level logged to my jpox.log file:

21:35:15,954 (main) DEBUG [JPOX.Datastore.Retrieve] - SELECT "P"."ID","P"."THE_PRICE" AS JPOXORDER0 FROM "JPA_PRODUCTS" "P" LEFT OUTER JOIN public."JPA_BOOKS" "SUBELEMENT0" ON "SUBELEMENT0"."ID" = "P"."ID" WHERE "SUBELEMENT0"."ID" IS NULL AND "P"."THE_PRICE" < .15E3 UNION SELECT "P"."ID","P"."THE_PRICE" AS JPOXORDER0 FROM "JPA_PRODUCTS" "P" INNER JOIN public."JPA_BOOKS" "ELEMENT" ON "ELEMENT"."ID" = "P"."ID" WHERE "P"."THE_PRICE" < .15E3 ORDER BY JPOXORDER0

Again, the database tables do have correctly inserted data:

david=# select * from "JPA_PRODUCTS";select * from "JPA_BOOKS" ;
 ID | DESCRIPTION | PRODUCT_NAME | THE_PRICE
----+------------------------------+--------------+-----------
 31 | A standard discman from Sony | Sony Discman | 200
(1 row)

 ID | AUTHOR | ISBN | PUBLISHER | DESCRIPTION | PRODUCT_NAME | THE_PRICE
----+-------------+----------+-----------------+-------------------+------------------------------+-----------
 32 | JRR Tolkien | 12345678 | MyBooks Factory | The classic story | Lord of the Rings by Tolkien | 49.99
(1 row)

The second point is that the delete fails to list 2 items deleted.

There are 2 types of errors in my logs:

21:45:55,288 (main) DEBUG [JPOX.Transaction] - [JPOX-015039] Running enlist operation on resource: org.jpox.store.rdbms.ConnectionFactoryImpl$EmulatedXAResource@1ce1bea, error code TMNOFLAGS and transaction: [JPOX Transaction, Transaction ID=Xid=^@^@^@^B, enlisted resources=[]]

And a rollback for the delete:

21:45:55,299 (main) DEBUG [JPOX.Persistence] - [JPOX-010004] ObjectManager internalFlush() process finished
21:45:55,299 (main) DEBUG [JPOX.Query] - [JPOX-021044] JPQL Query : Compiling "DELETE FROM Product p" [execution]
21:45:55,303 (main) DEBUG [JPOX.Query] - [JPOX-021045] JPQL Query : Compile Time = 4 ms
21:45:55,306 (main) DEBUG [JPOX.Transaction] - [JPOX-015002] Transaction rolling back for ObjectManager org.jpox.ObjectManagerImpl@a29c6e
21:45:55,306 (main) DEBUG [JPOX.Transaction] - [JPOX-015023] Transaction rolled back in 1 ms
21:45:55,306 (main) DEBUG [JPOX.Cache] - [JPOX-003011] Level 1 Cache cleared
21:45:55,306 (main) DEBUG [JPOX.Persistence] - [JPOX-010001] Object Manager "org.jpox.ObjectManagerImpl@a29c6e" closed

At this point I'm giving up on JPA and will start using JPOX in the JDO2 style.

Additionally, the documentation page step 6 has a few places where it lists org.jpox.samples.tutorial.jdo, not "jpa".

Regards,
David


Andy Jefferson added a comment - 06/Apr/08 08:43 PM
The docs are now updated thx.
The query generated with JPQL is wrong due to the inheritance strategy used (bug). If you set it to "JOINED" then it works fine - samples in SVN now has this.
The delete does correctly throw an exception saying that delete by query is not yet implemented, and the docs also mention this. There are other ways of deleting objects. Maybe the tutorial could do better but then we don't have time to do everything - left as an exercise for volunteers to contribute something better

Andy Jefferson added a comment - 16/Aug/12 02:56 PM
JPOX died some time ago

Andy Jefferson made changes - 16/Aug/12 02:56 PM
Field Original Value New Value
Status Open [ 1 ] Resolved [ 5 ]
Resolution Won't Fix [ 2 ]