Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-dev] Tolerance of bad/invalid JPQL

Why simply not to move the query definition to non-default orm-[pu_name].xml file?
Fair point.

What it boils down to is that I have an existing (OpenJPA based) application that is JPA provider agnostic and I want it to work with EclipseLink. Note, this application sticks strictly to the javax.persistence apis.

EclipseLink differs from OpenJPA in the way that it eagerly processes all NamedQueries at em creation time. OpenJPA delays processing a NamedQuery until the first time that an application tries to use it.




On Thu, Jul 24, 2014 at 9:09 AM, andrei ilitchev <andrei.ilitchev@xxxxxxxxxx> wrote:
Why simply not to move the query definition to non-default orm-[pu_name].xml file?
On 7/24/2014 9:36 AM, Tom Ware wrote:
I wonder if you could use our metadata source to achieve this.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/MetadataSource

i.e. Build a metadata source that would add the query dependent on what persistence unit you were using.

-Tom

On 23/07/2014 4:13 PM, Rick Curtis wrote:
I have a use case where there are multiple distinct persistence units defined in my persistence xml and each unit also has it's own non-default orm-[pu_name].xml file. The wrinkle in this scenario, is that there is also META-INF/orm.xml file that defines a named query that is only valid for one of my persistence units.

Everything works as expected for the persistence unit that the named query is valid for. The other persistence units are unusable as EntityManager creation fails with a PersistenceException[1].

I'm looking into providing a configurable option that would allow a user to tell EclipseLink to tolerate invalid/bad JPQL at EM creation time. I want a WARNING message to be logged when bad JPQL is encountered, but I want the EM to still be created/ mostly functional. If a user then attempts to create a bad named query at runtime, EclipseLink will throw an IllegalArgumentException. 

I've started to prototype support for this behavior, but am not certain if there is a better way to define/access a configuration property. The patch attached below seems to work if I pass this new property (eclipselink.jpql-tolerate-error) to Persistence.createEntityManagerFactory, or as a p.xml property. It doesn't work if the property is passed to emf.createEntityManager(props) call.

Thoughts on my approach? Am I heading in the right direction, or is there a better way to add this support?

Thanks,
Rick

ps -- I'm not sure if this list will allow me to send an attachment?


[1] ...
Caused by: Exception [EclipseLink-28019] (Eclipse Persistence Services - @VERSION@.@QUALIFIER@): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [invalid-named-query] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - @VERSION@.@QUALIFIER@): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT a FROM Alien a]. 
[14, 19] The abstract schema type 'Alien' is unknown.
at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:239)
... 32 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - @VERSION@.@QUALIFIER@): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT a FROM Alien a]. 
[14, 19] The abstract schema type 'Alien' is unknown.
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:155)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:347)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:278)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:163)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142)
at org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:221)
at org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:182)
at org.eclipse.persistence.queries.DatabaseQuery.prepareInternal(DatabaseQuery.java:621)
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQuery(AbstractSession.java:4348)
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:4306)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:579)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:799)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:743)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:253)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:702)
... 30 more

--
Rick Curtis


_______________________________________________
eclipselink-dev mailing list
eclipselink-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-dev



_______________________________________________
eclipselink-dev mailing list
eclipselink-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-dev


_______________________________________________
eclipselink-dev mailing list
eclipselink-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-dev



--
Rick Curtis

Back to the top