Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357177 - @NamedQuery is not able to resolve query names
Summary: @NamedQuery is not able to resolve query names
Status: RESOLVED DUPLICATE of bug 376995
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-08 21:27 EDT by Arun Gupta CLA
Modified: 2022-06-09 10:31 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arun Gupta CLA 2011-09-08 21:27:44 EDT
Build Identifier: EclipseLink 2.3.0

In NetBeans:

    Create a Java EE 6 project, enable CDI and JSF
    Use jdbc/sample database and generate JPA entities for any table
    Add the named queries as:

@NamedQueries({
@NamedQuery(name = "Sezzion.findAll", query = "SELECT s FROM Sezzion s"),
@NamedQuery(name = "Sezzion.findAllTracks", query = "SELECT DISTINCT s.TRACK FROM Sezzion s"),

The names should be "findAll" and other name should be "findAllXXX".

    Create an EJB and inject EntityManager:

@PersistenceContext
EntityManager em;

    Invoke any of the query in an EJB
    Use this EJB in an .XHTML page and view the page in a browser to see the error below:

Exception Description: Cannot add a query whose types conflict with an existing query. Query To Be Added: [ReadAllQuery(name="Sezzion.findAll" referenceClass=Sezzion jpql="SELECT s FROM Sezzion s")] is named: [Sezzion.findAll] with arguments [[]].The existing conflicting query: [ReadAllQuery(name="Sezzion.findAll" referenceClass=Sezzion jpql="SELECT s FROM Sezzion s")] is named: [Sezzion.findAll] with arguments: [[]].
at org.eclipse.persistence.exceptions.ValidationException.existingQueryTypeConflict(ValidationException.java:902)
at org.eclipse.persistence.internal.sessions.AbstractSession.addQuery(AbstractSession.java:422)
at org.eclipse.persistence.internal.sessions.AbstractSession.addQuery(AbstractSession.java:395)
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:2148)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:442)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:673)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:631)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:284)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:275)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:208)

if "Sezzion.findAllTracks" query is removed then everything works as expected.

Reproducible: Always

Steps to Reproduce:
In NetBeans:

    Create a Java EE 6 project, enable CDI and JSF
    Use jdbc/sample database and generate JPA entities for any table
    Add the named queries as:

@NamedQueries({
@NamedQuery(name = "Sezzion.findAll", query = "SELECT s FROM Sezzion s"),
@NamedQuery(name = "Sezzion.findAllTracks", query = "SELECT DISTINCT s.TRACK FROM Sezzion s"),

The names should be "findAll" and other name should be "findAllXXX".

    Create an EJB and inject EntityManager:

@PersistenceContext
EntityManager em;

    Invoke any of the query in an EJB
    Use this EJB in an .XHTML page and view the page in a browser to see the error below:

Exception Description: Cannot add a query whose types conflict with an existing query. Query To Be Added: [ReadAllQuery(name="Sezzion.findAll" referenceClass=Sezzion jpql="SELECT s FROM Sezzion s")] is named: [Sezzion.findAll] with arguments [[]].The existing conflicting query: [ReadAllQuery(name="Sezzion.findAll" referenceClass=Sezzion jpql="SELECT s FROM Sezzion s")] is named: [Sezzion.findAll] with arguments: [[]].
at org.eclipse.persistence.exceptions.ValidationException.existingQueryTypeConflict(ValidationException.java:902)
at org.eclipse.persistence.internal.sessions.AbstractSession.addQuery(AbstractSession.java:422)
at org.eclipse.persistence.internal.sessions.AbstractSession.addQuery(AbstractSession.java:395)
at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:2148)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:442)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:673)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:631)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:284)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:275)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:208)

if "Sezzion.findAllTracks" query is removed then everything works as expected.
Comment 1 Arun Gupta CLA 2011-09-08 21:28:22 EDT
Filed as a GlassFish bug at:

http://java.net/jira/browse/GLASSFISH-17283

Occurs in GlassFish 3.1.1
Comment 2 Tom Ware CLA 2011-09-22 11:42:10 EDT
Through discussion it appears this issue is the one described here:

http://old.nabble.com/Decrypting-error-message-td32222029.html 

Basically, if there is an incorrectly defined JPQL Named query, we log an exception, but continue with our deployment and this results in an error the 2nd time the factory is deployed.

The question is whether we should completely fail in this case, or contine to log the exception and ensure the other queries work.  I favour the latter.

Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Chris Delahunt CLA 2013-03-27 10:21:56 EDT
This looks like a duplicate of bug 376995 - "Invalid named JPQL Query causes invalid session to stick around, throw confusing exceptions".  Any exception during query processing would have been thrown and prevented deployment leaving the internal session object in an incomplete state.  Getting the entityManager after a failed deployment would cause redeployment, resulting in the exception seen here.

*** This bug has been marked as a duplicate of bug 376995 ***
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:31:19 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink