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.
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.
1-6 may be appropriate if no driver is selected, 7-10 is in db area
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?
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?
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'
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?
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.
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.
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.
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.
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
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.
(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.