openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roger.keays" <roger.ke...@ninthavenue.com.au>
Subject Re: WHERE clauses with ORDER BY subclass field
Date Wed, 12 Dec 2007 08:02:45 GMT



roger.keays wrote:
> 
> I've noticed that in 1.0.0, 1.0.1 and 1.1.0-SNAPSHOT I cannot combine
> WHERE and ORDER BY if they both use subclass fields. This wasn't a problem
> in 0.9.7
Correction: this hasn't changed since 0.9.7. The problem has appeared since
I switched from using mapping files to annotations.

Perhaps somebody here could have a look at how I am bootstrapping the EMF.
The regular methods using persistence.xml aren't flexible enough for us, so
we do it programatically using the following code:

        PersistenceUnitInfoImpl pui = new PersistenceUnitInfoImpl();
        Boolean hasEntities = false;
        if (mappingFiles != null) {
            for (String mapping : mappingFiles) {
                pui.addMappingFileName(mapping);
                hasEntities = true;
            }
        }
        if (entities != null) {
            for (String entity : entities) {
                pui.addManagedClassName(entity);
                hasEntities = true;
            }
        }
        if (hasEntities) {
            PersistenceProductDerivation pd = new
PersistenceProductDerivation();
            try {
                ConfigurationProvider cp = pd.load(pui, allConfig);
                BrokerFactory factory = Bootstrap.newBrokerFactory(cp, 
                    pui.getClassLoader());
               
site.setEmf(JPAFacadeHelper.toEntityManagerFactory(factory));
            } catch (Exception e) {
                throw PersistenceExceptions.toPersistenceException(e);
            }
        }

Could this be causing the problem? It seems strange that it works using
mapping files, but not when we provide a list of annotated entity class
names.

Thanks in advance,

Roger



> e.g. these queries work (id is a subclass field, uuid is a superclass
> field):
> 
>  SELECT i FROM News i ORDER BY i.id;
>  SELECT i FROM News i WHERE i.id > 1;
>  SELECT i FROM News i WHERE i.uuid > 1 ORDER BY i.uuid;
>  SELECT i FROM News i WHERE i.id > 1 ORDER BY i.uuid;
>  SELECT i FROM News i WHERE i.uuid > 1 ORDER BY i.id;
> 
> but this query fails:
> 
>  SELECT i FROM News i WHERE i.id > 1 ORDER BY i.id;
> 
> the stack trace follows.
> 
> Caused by: <openjpa-1.0.0-r420667:570500 nonfatal general error>
> org.apache.openjpa.persistence.Persiste
> nceException: ERROR: missing FROM-clause entry for table "t0" {prepstmnt
> 26955692 SELECT t1.uuid, t2.id,
>  t2.comment, t2.inheritable, t2.level, t2.role, t2.type, t2.username FROM
> FB_METADATA t1 INNER JOIN FB_P
> RIVILEGES t2 ON t1.uuid = t2.item_uuid WHERE (t0.id > ?) ORDER BY t1.uuid
> ASC [params=(long) 1]} [code=0
> , state=42P01]
>         at
> org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:3849)
>         at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97)
>         at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:83)
>         at
> org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:59)
>         at
> org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.handleCheckedException(SelectResult
> ObjectProvider.java:155)
>         at
> org.apache.openjpa.datacache.QueryCacheStoreQuery$CachingResultObjectProvider.handleCheckedEx
> ception(QueryCacheStoreQuery.java:634)
>         at
> org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:40)
>         at
> org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1223)
>         at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:990)
>         at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:799)
>         at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:769)
>         at
> org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:533)
>         at
> org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:235)
>         at
> org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:277)
>         at furnace.core.el.EntityFunctions.query1(EntityFunctions.java:71)
> 
> t0 should be FB_NEWS
> 

-- 
View this message in context: http://www.nabble.com/WHERE-clauses-with-ORDER-BY-subclass-field-tp14290053p14290536.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message