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 237922 - NullPointerException with Firebird in wizard "Hibernate Mapping Files And POJOs from database"
Summary: NullPointerException with Firebird in wizard "Hibernate Mapping Files And POJ...
Status: RESOLVED WONTFIX
Alias: None
Product: javaee
Classification: Unclassified
Component: Hibernate (show other bugs)
Version: 7.4
Hardware: PC Windows 8 x64
: P3 normal (vote)
Assignee: Sergey Petrov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-03 16:29 UTC by mrotteveel
Modified: 2016-07-07 08:54 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mrotteveel 2013-11-03 16:29:34 UTC
The hibernate wizard "Hibernate Mapping Files And POJOs from database" has a NullPointerException when connecting to a Firebird database:

226109 [AWT-EventQueue-0] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider
INFO [org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider]: Loaded JDBC driver 
INFO [org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider]: Got connection.. returning
INFO [org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor]: access to hibernate fails.
java.lang.NullPointerException
	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:115)
	at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2855)
	at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:41)
	at org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor.checkConfig(HibernateCodeGenWizardDescriptor.java:289)
[catch] at org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor.isValid(HibernateCodeGenWizardDescriptor.java:179)
	at org.openide.WizardDescriptor.updateStateOpen(WizardDescriptor.java:874)
	at org.openide.WizardDescriptor.updateState(WizardDescriptor.java:822)
	at org.openide.loaders.TemplateWizard.updateState(TemplateWizard.java:754)
	at org.netbeans.modules.project.ui.NewFileWizard.updateState(NewFileWizard.java:135)
	at org.openide.WizardDescriptor._updateState(WizardDescriptor.java:800)

After digging into the code of Netbeans and adding extra logging to Jaybird, I found that the problem is that Netbeans loads the driver with a custom classloader that doesn't return resources in /META-INF/services. 

Jaybird (the Firebird JDBC driver) uses plugins for its protocol implementation (eg the Type 4 implementation, Type 2 native, Type 2 embedded). These are listed in a file in /META-INF/services/ (specifically /META-INF/services/org.firebirdsql.gds.impl.GDSFactoryPlugin), and are loaded with a mechanism similar to java.util.ServiceLoader. This also allows third-parties to add protocol implementations. For example as a workaround, or for special needs; I know a company used this mechanism to provide a driver that could translate Oracle syntax to Firebird.

The change were a Netbeans classloader ignores the existence of all files in /META-INF/services was added in:
http://hg.netbeans.org/main-silver?cmd=changeset;node=c8413dd446c2
in response to bug:
https://netbeans.org/bugzilla/show_bug.cgi?id=194915

I have added a workaround in Jaybird, but I think it is a bug in Netbeans that it purposefully refuses to load files that may be required by a Java library.

See also:
http://tracker.firebirdsql.org/browse/JDBC-325
http://stackoverflow.com/a/18920383/466862
http://stackoverflow.com/questions/18921352/using-meta-inf-services-for-internal-plumbing-of-driver

Reproducing this requires Jaybird 2.2.3 or earlier, as I added a workaround to the upcoming Jaybird 2.2.4.

When investigating this, I noticed that when going through the wizard, *two* database connections are made: 
one by org.netbeans.modules.hibernate.util.HibernateUtil that succeeds but isn't used, 
and another by org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider which fails because of the classloading issue described in my previous comment.

This bug is related to 202333 and 212636
Comment 1 Martin Balin 2016-07-07 08:54:28 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss