简体   繁体   中英

Netbeans run JPQL query not working

I have made CRUD application using EJB + JPA using JBoss server, which works perfectly fine. But I am unable to run JPQL query in netbeans from persistence file. Please find below configuration.

JBoss 7 datasource :

<datasource jta="true" jndi-name="java:/jboss/darshan" pool-name="com.discusit.darshan_darshan-ejb_ejb_1.0PU" enabled="true" use-ccm="false">
    <connection-url>jdbc:postgresql://localhost:5432/darshan</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <driver>postgresql</driver>
    <security>
        <user-name>darshan</user-name>
        <password>darshan</password>
    </security>
    <validation>
        <validate-on-match>false</validate-on-match>
        <background-validation>false</background-validation>
    </validation>
    <statement>
        <share-prepared-statements>false</share-prepared-statements>
    </statement>
</datasource>

persistence.xml :

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="com.discusit.darshan_darshan-ejb_ejb_1.0PU" transaction-type="JTA">
        <jta-data-source>java:/jboss/darshan</jta-data-source>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties/>
    </persistence-unit>
</persistence>

Kindly note, I am able to auto complete my tables but when I run I found below errors.

java.lang.Exception: You need to add your persistence provider library either to project classpath or registed as Ant Library within Netbeans

or

java.lang.Exception: You need to specify either database connection or datasource in persistence.xml.

Let me know if you need any other information.

  1. Make sure that you have valid instance of your application server (your case JBoss) in Servers under Services tab.

  2. in your application Properties -> Run : Select your server (JBoss) .

  3. Make sure that you have valid Database connection to your schema in Databases under Services tab (be sure that it has same credentials as in your Data Source configuration in your application server).

  4. Insure that you have already added your entity classes in your persistence.xml.

  5. Download your JPA provider library, and add it to your Project from

    Properties -> Libraries : Add Library .

In case you use maven :

just add dependency of your JPA provider

(insure that you NOT include this tag "<scope>provided</scope>" during running JPQL, but add it before compiling as your application server will provide it).

Hope it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM