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 215480 - can't create entity classes from XA data source
Summary: can't create entity classes from XA data source
Status: RESOLVED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Jiri Rechtacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-12 18:49 UTC by gholmer
Modified: 2012-12-10 08:32 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Patch (4.25 KB, patch)
2012-12-06 16:41 UTC, Jaroslav Havlin
Details | Diff
Patch - Don't allow to register invalid driver class (5.20 KB, patch)
2012-12-07 11:58 UTC, Jaroslav Havlin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description gholmer 2012-07-12 18:49:02 UTC
1) Create connection pool and JDBC resource in GlassFish 3.1.1 using PostgreSQL 9.1 driver (postgresql-9.1-902.jdbc4.jar). Specify resource type java.sql.XADataSource and datasource classname org.postgresql.xa.PGXADataSource.
2) Test to verify that GlassFish pool works correctly.
3) Create EJB project set to use instance of GlassFish from step 1.
4) Right-click project and select New/Entity Classes From Database.
5) In the Data Source dropdown, select the JDBC resource from step 1.
6) Result is an error dialog with text "Unable to find the driver org.postgresql.xa.PGXADataSource. Register this driver in the Databases tab."
7) Go to Services/Databases. Right-click Drivers tab and select "New Driver".
8) Select same driver file from step 1 and specify driver class org.postgresql.xa.PGXADataSource.
9) Right-click driver in database tab and try to create a connection with it (using URL e.g. jdbc:postgresql://localhost:5432/slm3).
10) Result is "Cannot establish a connection to jdbc:postgresql://localhost:5432/slm3 using java.sql.XADataSource (Unable to find a suitable driver)."

So I can't create the entity classes because the driver isn't set up in the Databases tab, but I can't set up the driver in the Databases tab either.

Note that a NetBeans web project that uses the GlassFish JDBC pool and resource from step 1 works just fine.
Comment 1 Sergey Petrov 2012-09-20 11:03:54 UTC
1-6 may be appropriate if no driver is selected,
7-10 is in db area
Comment 2 Jaroslav Havlin 2012-12-06 16:41:11 UTC
Created attachment 128993 [details]
Patch

The problem is that org.postgresql.xa.PGXADataSource does not implement interface java.sql.Driver. DataSource is not a Driver. GlassFish can use it, but NetBeans not.

So the solution is not trivial. Possibilities are:

1) Try to find a driver class when a DataSource class is specified in driver
   properties (create driver dialog).
   See the attached patch. This is not optimal, as you have to register 
   a new driver, which in fact uses another driver class than specified.
   But it needs to be there to match the GlassFish JDBC resource.

   Maybe this should be handled in Persistence module rather than in DB module.

2) Only show JDBC resources that specify Drivers, not DataSources. This would
   probably end up in forcing users to create another JDBC resources that use
   Drivers instead of DataSources. So, again, you need to register something
   extra to make the functionality work.

3) Search all registered JARs, find which of them contains the DataSource class,
   and use Driver contained in that JAR. This could be quite expensive and 
   seems to be an overkill.

Sergey, what do you think?
Comment 3 Petr Jiricka 2012-12-06 17:25:09 UTC
Jardo, so will the attached patch work in the specific case of postgresql-9.1-902.jdbc4.jar? I.e. if I add this file as a driver (step 8 in Glen's original steps), will the IDE be happy and will it start to work?
Comment 4 Sergey Petrov 2012-12-06 20:00:32 UTC
Another option we may say we just do not support org.postgresql.xa.PGXADataSource and other cases without Driver implementation, new connection dialog may show some message 'it's not a driver' and do not allow to create a connection. yes, in this case entities will not be possible to create without extra steps.
I prefer (2) + some handling, implemet part of the patch but in case of datasource do not try to find something and just throw 'it's not a driver' or similar exception/message instead of 'can't find suitable driver'
Comment 5 Sergey Petrov 2012-12-06 20:02:45 UTC
may be this check can be done when new driver is registered instead of when new connection is created is there any usecase where driver with not Driver is usable?
Comment 6 Jaroslav Havlin 2012-12-07 11:58:28 UTC
Created attachment 129039 [details]
Patch - Don't allow to register invalid driver class

(In reply to comment #3)
> Jardo, so will the attached patch work in the specific case of
> postgresql-9.1-902.jdbc4.jar? I.e. if I add this file as a driver (step 8
> in Glen's original steps).
Yes, it would work also with most of other drivers.

> Will the IDE be happy and will it start to work?
I'm afraid the IDE might be quite sad, because it has to lie to the user about the driver class. It shows that driver class is PGXADataSource, but in fact
org.postgresql.Driver is used instead. But the user may be happy.

(In reply to comment #4)
> I prefer (2) + some handling, implemet part of the patch but in case of
> datasource do not try to find something and just throw 'it's not a driver' or
> similar exception/message instead of 'can't find suitable driver'
I agree, that would be cleaner. Instead of registering "fake" driver, the user would have to create another JDBC resource. Which seems more transparent to me.

Please check the attached patch.

What about showing a info message about the fact that some non-driver JDBC resources were detected and that they are not (and cannot be) supported by the IDE? For example under the "Data Source:" combo box.
Comment 7 Sergey Petrov 2012-12-07 14:09:08 UTC
yes, nice idea to have as disabled items with text like "jdbc/sample(non java.sql.Driver resource), in this case it can be handled on persistence side only but patch seems ok too.
Comment 8 Jaroslav Havlin 2012-12-07 14:37:34 UTC
Thank you, the patch was integrated:
http://hg.netbeans.org/core-main/rev/2c15c079846c

Another solution would be to allow users to manually assign NetBeans Database Connections to server-side JDBC resources.
This would solve some other problems, e.g. database server has different name when accessed from GlassFish and when accessed from developer's computer.
(Not sure it is worth implementing, these situation may be very rare.)

I'm assigning the bug back. Please let me know if I should fix something in DB module. Thanks.
Comment 9 Sergey Petrov 2012-12-07 21:38:58 UTC
currently I see a problem with realization for some check on persistence side as if I have no access to registred pair of "bad" not-driver + jar I may not be able to load this class and check if it's a Driver or not.
Comment 10 Quality Engineering 2012-12-09 03:09:22 UTC
Integrated into 'main-golden', will be available in build *201212090001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/2c15c079846c
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #215480: Check that DB driver class is really a java.sql.Driver
Comment 11 Sergey Petrov 2012-12-09 07:57:21 UTC
it seems fixed as much as possible now, user will get 'no connection' and on attempt to create a driver will get 'it's not a driver', hard to implement mine suggestion above.
Comment 12 Jaroslav Havlin 2012-12-10 08:32:22 UTC
(In reply to comment #11)
> it seems fixed as much as possible now, user will get 'no connection' and on
> attempt to create a driver will get 'it's not a driver', hard to implement mine
> suggestion above.
I understand and agree. Thank you, Sergey.