This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 241897

Summary: No suitable driver found when executing JPQL query with a non bundled jdbc driver
Product: javaee Reporter: alied <alied>
Component: PersistenceAssignee: Sergey Petrov <sj-nb>
Status: RESOLVED WONTFIX    
Severity: normal CC: MackSix, pjiricka
Priority: P3    
Version: 8.0   
Hardware: PC   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description alied 2014-02-14 22:53:40 UTC
[ BUILD # : 201402140001 ]
[ JDK VERSION : 1.7.0_45 ]

ENVIRONMENT:
Product Version: NetBeans IDE Dev (Build 201402140001)
Java: 1.7.0_51; Java HotSpot(TM) 64-Bit Server VM 24.51-b03
Runtime: Java(TM) SE Runtime Environment 1.7.0_51-b13
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
User directory: C:\Users\alied.perez\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\alied.perez\AppData\Local\NetBeans\Cache\dev

STEPS:
-Add new driver (e.g. jtds driver(http://sourceforge.net/projects/jtds/files/))
-Add new database connection and ensure the connection works properly (Run some
query and check the results)
-Create new Maven Java application project
-Import some entities from DB. Make sure persistence.xml is created.
-Righ-click persistence.xml and select "run JPQL query"
-Run some trivial query like "SELECT e FROM Entity e", or any other available
in the created Entities

ACTUAL:
Error:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse
Persistence Services - 2.5.1.v20130918-f2b9fc5):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for
jdbc:jtds:sqlserver://(url removed)
Error Code: 0
        at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManager
SetupImpl.java:766)
        at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSes
sion(EntityManagerFactoryDelegate.java:204)
        at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityMa
nagerImpl(EntityManagerFactoryDelegate.java:304)
        at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManage
rImpl(EntityManagerFactoryImpl.java:336)
        at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManage
r(EntityManagerFactoryImpl.java:302)
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for
jdbc:jtds:sqlserver://(url removed)
Error Code: 0
        at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseExcept
ion.java:331)
        at
org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseExcept
ion.java:326)
        at
org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:
138)
        at
org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceL
ogin.java:162)
        at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasou
rce(DatabaseSessionImpl.java:204)
        at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectData
source(DatabaseSessionImpl.java:741)
        at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityMa
nagerFactoryProvider.java:239)
        at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManager
SetupImpl.java:685)
        ... 6 more
Caused by: java.sql.SQLException: No suitable driver found for
jdbc:jtds:sqlserver://(url removed)
        at java.sql.DriverManager.getConnection(DriverManager.java:596)
        at java.sql.DriverManager.getConnection(DriverManager.java:187)
        at
org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:
98)
        ... 11 more

EXPECTED:
The query results are shown.
Comment 1 Sergey Petrov 2014-02-15 00:55:31 UTC
if query will not work in the application, i.e. if to start this maven java project, it will not work in nb environment also. it's expected result.
on other side jpql executor tries to find suitable driver in case if it's registered in nb, may be jtds isn't recognized by some code.
Comment 2 Sergey Petrov 2014-02-15 00:59:21 UTC
as a workaround it should work to add the driver to application classpath
Comment 3 alied 2014-02-17 14:54:36 UTC
(In reply to Sergey Petrov from comment #2)
> as a workaround it should work to add the driver to application classpath

You mean adding jtds as a dependency on the POM?
No, that does not work either. I missed that step, but it does not fix it (tested it again).
Also, the SQL pane keeps telling me to build the application.

So:
1- It's not a JDBC URL issue. Te IDE-registered connection works fine.
2- The driver is a dependency of the application.

The issue seems to be with drivers not bundled with the IDE (e.g. jtds).
Comment 4 alied 2014-02-17 15:21:28 UTC
(In reply to Sergey Petrov from comment #1)
> if query will not work in the application, i.e. if to start this maven java
> project, it will not work in nb environment also. it's expected result.

The tested query is one created by the "Create Entities from database" and the most trivial one: "SELECT e FROM Entity e"

> on other side jpql executor tries to find suitable driver in case if it's
> registered in nb, may be jtds isn't recognized by some code.

The driver works from Services/Databases/connection and from the application. The persistence.xml is created with that connection.
Comment 5 Sergey Petrov 2014-02-17 16:32:45 UTC
ok, it's strange, need to setup environment to evaluate
Comment 6 Sergey Petrov 2014-02-17 18:51:40 UTC
What server should I install?
Comment 7 alied 2014-02-17 19:01:35 UTC
(In reply to Sergey Petrov from comment #6)
> What server should I install?

I tried with both MS SQL Server 2008 and 2012 (both failed)
Comment 8 MackSix 2014-02-18 05:24:40 UTC
I tried to get the PetCatalog demo to use it and I get the same results.

I tried putting the driver (jtds-1.3.1.jar) in the NetBeans ide/modules/ext folder and added the jar to the libraries folder in the project to no avail.

The connection in the Services tabs works and queries the database fine. (MS SQL Server 2012 Express)
Comment 9 MackSix 2014-02-18 05:25:42 UTC
(In reply to Sergey Petrov from comment #5)
> ok, it's strange, need to setup environment to evaluate

When you install SQL Server 2012, run the SQL Server configuration manager and enable TCP/IP under the SQL Server Network Configuration and then look at the Properties for the SQL Server Browser and under the Service tab, change the start mode to manual or automatic and then start the SQL Server Browser.

I put the jTDS ntlmauth.dll in the Windows folder and running Windows Authentication.
Comment 10 Sergey Petrov 2014-02-18 19:15:49 UTC
ok, thanks.
I see this exception is different from an exception in case if jdbc jar isn't added to classpath and an application is executed. 
Unfortunately corresponding jar is added to jpql execution classpath and the cause is somewhere else.
Comment 11 alied 2014-02-18 23:24:23 UTC
Can we raise priority on this one?
Comment 12 Sergey Petrov 2014-02-19 21:42:05 UTC
regarding priority, at current state it doesn't matter much in order to fix in 8.0, I'm evaluation right now, but in case it can't be fixed fast, it's more likely to add a message like "sorry jtds isn't supported" as a fix.

also, real problem behind is "I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property."  It's hidden by eclipselink which re-throw the exception. 
jtds can't load dll it require for windows authentication if executed the way it's required for jql execution,  But common solutions do not work foe me in this case.

suppose it may work in case of sql authentication but haven't tried.
Comment 13 Sergey Petrov 2014-02-19 22:33:04 UTC
just tried with sa login access, and jpql execution works fine in this case.
Comment 14 MackSix 2014-02-20 00:42:30 UTC
I finally figured out how to add a SQL Server Login and it connects if I do a JPQL query, but I don't know how to do a JPQL query and it tells me "Item" is unknown. :)


SELECT i FROM Item i WHERE i.itemid = 10
Comment 15 Sergey Petrov 2014-02-20 10:46:03 UTC
it's another issue, even your connection have some schema marked as default, you have to specify schema in @Table for your entities
Comment 16 Sergey Petrov 2014-07-22 13:49:03 UTC
sorry, I do not see ability to fix it yet, you have to use sql access instead of native windows as requirement/workaround  I don't have much control on native calls from microsoft sql driver and it's hard to investigate this area also.