users@glassfish.java.net

JPA: TRUE, order by boolean, outer join...

From: Gabor Szokoli <szocske_at_gmail.com>
Date: Thu, 15 Nov 2007 10:26:04 +0100

Hi,

I see a lot of non-glassfish-specific JPA traffic here, is it
considered on-topic here?

If so, I have stumbled upon some obstacles:

I do use glassfish (v2) with bundled toplink, Postgresql 8.2 underneath.

1, While creating EJBQL queries algorithmically, I tried to use "TRUE"
as the null-clause in the WHERE part of the query to conjunct other
clauses to, if any.
But this is what I get:
 Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0 (Build
b58g-fcs (09/07/2007))):
oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Syntax error parsing the query [SELECT COUNT
(e) FROM FileMetaInfo e WHERE TRUE ], line 1, column 46: unexpected
token [TRUE].
Internal Exception: line 1:46: unexpected token: TRUE
        at oracle.toplink.essentials.exceptions.EJBQLException.unexpectedToken(EJBQLException.java:389)



I can't use "1=1" either, if I do, when the query is executed as SQL,
the table is included twice in the FROM part:
SELECT DISTINCT OBJECT (e) FROM FileMetaInfo e WHERE 1=1 ORDER BY e.id asc
SELECT DISTINCT t0.ID, t0.ARCHIVE_TYPE, t0.DELETED, t0.UNIQUEID,
t0.LOCATION, t0.FTYPE, t0.MD5SUM, t0.RTIME, t0.REMOTECLUSTERID,
t0.ARCHIVED_TO,
 t0.ORIGNAME, t0.SOURCE FROM filemetainfo t0, filemetainfo t1 WHERE (?
= ?) ORDER BY t0.ID ASC
        bind => [1, 1]

Just an inconvenience now, I solve it by "e.id IS NOT NULL", but
indicates problems with my understanding of EJBQL :-)

2, I can't ORDER BY a boolean entity attribute:
Exception [TOPLINK-8021] (Oracle TopLink Essentials - 2.0 (Build
b58g-fcs (09/07/2007))):
oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Error compiling the query [SELECT DISTINCT
OBJECT (e) FROM FileMetaInfo e WHERE e.id IS NOT NULL ORDER BY
e.deleted asc], line 1, column 84: invalid ORDER BY item [e.deleted]
of type [java.lang.Boolean], expected expression of an orderable type.
     at oracle.toplink.essentials.exceptions.EJBQLException.expectedOrderableOrderByItem(EJBQLException.java:359)

Works fine in SQL, works even in JPA if I map the boolean table column
to an Integer entity attribute as an experiment.

3, Can I mark a Many-To-One relation on an entity to default to an
outer join instead of the current default "manual" join (WHERE
foreingkey=privatekey) without explicitly joining the related entities
in each EJBQL query?
I'd like to be able to write
SELECT e FROM MyClass AS e ORDER BY e.related.attributeofrelated
instead of
SELECT e FROM MyClass AS e LEFT OUTER JOIN e.related as related ORDER
BY related.attributeofrelated


Thank you.