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?
[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