You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Richard Grin <Ri...@univ-cotedazur.fr> on 2019/07/23 17:48:09 UTC

Is "Run JPQL Query" working?

Hi,

NetBeans 11.1 beta 4 (I have not installed the final version yet).

I can't use the tool to test the JPQL queries with a right click on 
persistence.xml > "Run JPQL Query".

The JPQL query: "select c from Customer c" with the sample database 
provided by the installation. I have generated the entities with New > 
"Entity Classes From Database...".

I receive this message: javax.persistence.PersistenceException: No 
Persistence provider for EntityManager named null
     at 
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" 
xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
   <persistence-unit name="samplePU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     <jta-data-source>jdbc/sample</jta-data-source>
     <properties>
       <property name="eclipselink.logging.level" value="FINE"/>
     </properties>
   </persistence-unit>
</persistence>

Any help?

Richard Grin


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
For additional commands, e-mail: users-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: Is "Run JPQL Query" working?

Posted by Richard Grin <Ri...@univ-cotedazur.fr>.
Hi Geertjan,

Simple and quick to reproduce:

  1. Create a new Maven Web Application Project (Java EE 8). Associate it with Payara 5.192 server.

  2. Right click on the new project and New Entity classes from database. Choose the sample database (Java DB). Add the CUSTOMER table. Any package for the entities (i.e. entities). Finish.

  3. Some code must be added into persistence.xml. This step is necessary because there is a very annoying problem I have already reported in a previous message: no match between the "design" and the "source" view of persistence.xml. With the previous versions of NetBeans, these lines were automatically added into the file. Now it is "added" in the design view but not into the file!

Add jta-data-source and provider in persistence.xml:

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/sample</jta-data-source>

Add transaction-type="JTA" too.

Finally:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://java.sun.com/xml/ns/persistence"<http://java.sun.com/xml/ns/persistence> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"<http://xmlns.jcp.org/xml/ns/persistencehttp://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd>>
  <!-- Define Persistence Unit -->
  <persistence-unit name="my_persistence_unit" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/sample</jta-data-source>
    <properties>
      <property name="eclipselink.logging.level" value="FINE"/>
    </properties>
  </persistence-unit>
</persistence>

4. Start Payara and Run the application; no problem, "Hello World!" in the brower (is this step necessary?)

5. Right click on persistence.xml > Run JPQL Query and type
select c from Customer c

The error message:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named samplePU
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)

If I had dependencies in pom.xml for the group org.eclipse.persistence, the error changes:

javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/sample].
Internal Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:766)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302)
Caused by: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/sample].
Internal Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:520)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:204)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:741)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:239)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:685)
    ... 6 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
    at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:685)
    at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
    at java.naming/javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:402)
    at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:413)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more


However if I add some code to the project for JSF, the project works well without any error to display the data of the database linked to the data source jdbc/sample. So the problem happens only with this "Run JPQL Query". Perhaps the context is not the same during the running of the application and the running of "Run JPQL Query"?

Richard

PS: the code in pom.xml for org.eclipse.persistance:

        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.core</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.asm</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.antlr</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa.jpql</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.1.0</version>
        </dependency>

Le 24/07/2019 à 18:23, Geertjan Wielenga a écrit :
Will take a look, best will be if you file an issue, steps to reproduce, etc.

Gj

On Wed, 24 Jul 2019 at 17:54, Richard Grin <Ri...@univ-cotedazur.fr>> wrote:
Hi Geertjan,

You wrote a short article in your blog on this feature a few years ago.
Do you know if it still works?

Regards,

Richard

Le 23/07/2019 à 19:48, Richard Grin a écrit :
> Hi,
>
> NetBeans 11.1 beta 4 (I have not installed the final version yet).
>
> I can't use the tool to test the JPQL queries with a right click on
> persistence.xml > "Run JPQL Query".
>
> The JPQL query: "select c from Customer c" with the sample database
> provided by the installation. I have generated the entities with New >
> "Entity Classes From Database...".
>
> I receive this message: javax.persistence.PersistenceException: No
> Persistence provider for EntityManager named null
>       at
> javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
>
> persistence.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="2.2"
> xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
> http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
>     <persistence-unit name="samplePU">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
>       <jta-data-source>jdbc/sample</jta-data-source>
>       <properties>
>         <property name="eclipselink.logging.level" value="FINE"/>
>       </properties>
>     </persistence-unit>
> </persistence>
>
> Any help?
>
> Richard Grin
>
--
Cordialement,

Richard Grin