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

I wonder if you could use our metadata source to achieve this.

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


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?


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(
... 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(
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(
at org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(
at org.eclipse.persistence.internal.jpa.JPAQuery.prepare(
at org.eclipse.persistence.queries.DatabaseQuery.prepareInternal(
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQuery(
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(
... 30 more

Rick Curtis

eclipselink-dev mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit

Back to the top