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 231916 - [74cat]GUI Builder broken for Hibernate Connected Components
Summary: [74cat]GUI Builder broken for Hibernate Connected Components
Status: RESOLVED INVALID
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Tomas Pavek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-27 10:13 UTC by bolsover
Modified: 2013-08-09 11:40 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Modified Sample project (24.19 KB, application/octet-stream)
2013-06-27 10:13 UTC, bolsover
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bolsover 2013-06-27 10:13:12 UTC
Created attachment 136393 [details]
Modified Sample project

I have attached a modified version of the DVDStoreAdmin project to illustrate the issue..

To run the project, you will need MySQL default sample sakila database and you will need to enter the appropriate connection password into htbernate.cfg.xml and resolve any library references for the MySQl jdbc connector.

Under NB 7.3.1 and earlier, the project should run fine and you should be able to open and run both the original sample DVDStoreAdmin GUI and BrokenFrame.

Under NB 7.4 however, BrokenFrame will issue a Form Loaded with Errors warning with the exceptions:

java.lang.ClassNotFoundException: sakila.ui.ActorComboBox
	at org.netbeans.modules.form.project.ProjectClassLoader.findClass(ProjectClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.netbeans.modules.form.project.FormClassLoader.findClass(FormClassLoader.java:83)

db
Comment 1 bolsover 2013-06-27 20:04:05 UTC
Bumped this up to P2 - for me this would be a show stopper!
Comment 2 bolsover 2013-06-27 20:05:09 UTC
Bumped this up to P2 - for me this would be a show stopper!
Comment 3 Sergey Petrov 2013-07-09 12:05:50 UTC
hibernate library was updated, it's likely related.
Comment 4 Sergey Petrov 2013-07-09 12:56:22 UTC
may be caused by loading of dom4j in 
org.netbeans.modules.form.project.ProjectClassLoader
and
org.netbeans.modules.hibernate.util.CustomClassLoader
Comment 5 Lou Dasaro 2013-07-09 13:51:59 UTC
I just wanted to mention that some update(? plug-in maybe?)) caused my JavaFX application to crash during the first accesses of Hibernate in 7.3 and 7.3.1 where previously in those versions the app had been working fine.  My point is that, under 7.4 dev (with the upgraded Hibernate) the app now builds and runs fine. Let me know if you think I should work up a bug report for this - it seems moot if it stays fixed in 7.4
Comment 6 bolsover 2013-07-09 13:53:03 UTC
(In reply to comment #3)
> hibernate library was updated, it's likely related.

I have also tested with much later versions of hibernate (I currently use 4.1.8.Final) and see the same problem.
Comment 7 bolsover 2013-07-09 13:57:06 UTC
(In reply to comment #5)
> I just wanted to mention that some update(? plug-in maybe?)) caused my JavaFX
> application to crash during the first accesses of Hibernate in 7.3 and 7.3.1
> where previously in those versions the app had been working fine.  My point is
> that, under 7.4 dev (with the upgraded Hibernate) the app now builds and runs
> fine. Let me know if you think I should work up a bug report for this - it
> seems moot if it stays fixed in 7.4

I suspect this is a different problem - the specific issue i have is with the GUI builder failing to load components that depend on a hibernate connection.
Comment 8 bolsover 2013-07-09 13:58:31 UTC
(In reply to comment #4)
> may be caused by loading of dom4j in 
> org.netbeans.modules.form.project.ProjectClassLoader
> and
> org.netbeans.modules.hibernate.util.CustomClassLoader

Sergey, can you be more specific; is this something I can test/work around?
Comment 9 Sergey Petrov 2013-07-09 14:32:00 UTC
As far as I'm responsible for hibernate area, I've done some brief evaluation and it seems forms module do not use hibernate module here and hibernate custom classloader isn't invoked also. In this case it's likely should be addressed on forms side. If it's "two classloaders" issue, it should be somewhere else. Google show some similar problems in deployment of hibernate applications on some servers but hints may not work for forms module.

I don't know any workaround so far on hibernate/application side, if project configuration may be updated manually to avoid this exception, I can update hibernate module to include some options by default(for example in hibernate.cfg or in generated hibernateutil etc).
Comment 10 bolsover 2013-07-09 14:39:55 UTC
(In reply to comment #9)

> "In this case it's likely should be addressed on forms side. "
Does this mean you'll be passing the issue on to guibuilder? department?

> If it's "two classloaders" issue, it should be somewhere else. 
Who?

I'm just concerned that this issue does not get dropped or kicked into the 'WONTFIX/CANTFIX' bucket.
Comment 11 Sergey Petrov 2013-07-09 14:51:44 UTC
It's already assined to guibuilder department, I just noted it in netcat thread and evaluate if it's directly dependent(or caused by) to hibernate module. 

I played a bit and if I use systemclassloader inside of org.netbeans.modules.form.project.ProjectClassLoader, I pass initial exception, but got some another. I hope someone from forms can look into the issue.
Comment 12 Jiri Kovalsky 2013-07-10 14:51:43 UTC
Tomasi, can you please evaluate this? Thanks a lot!
Comment 13 Sergey Petrov 2013-07-10 15:44:32 UTC
additional note: for me, I can't open the BrokenFrame in 7.3.1 also
Comment 14 bolsover 2013-07-10 16:19:01 UTC
(In reply to comment #13)
> additional note: for me, I can't open the BrokenFrame in 7.3.1 also

Can you run DVDStoreAdmin? If not then check hibernate.CFB.XML and database connection. 

BrokenFrame will only open without error in 7.3.1 if the hibernate database connection is correctly configured and the database is available.
Comment 15 Tomas Pavek 2013-08-08 13:07:33 UTC
Are you sure this worked before? Same as mentioned by Sergey I can't open the BrokenForm in 7.3(.1) either. I'm getting:

java.lang.ExceptionInInitializerError
  at sakila.util.HibernateUtil.<clinit>(HibernateUtil.java:30)
  at sakila.ui.ActorComboBox.<clinit>(ActorComboBox.java:26)
  at java.lang.Class.forName0(Native Method)
...

caused by a ClassCastException logged as:
org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
  at org.dom4j.io.SAXReader.read(SAXReader.java:484)
...

Note this is not related to whether I have the right database or not, here it fails to read the hibernate.cfg.xml file.

I'm getting this same exception from NB 7.3 as well as from current dev 7.4.

The (part of) ClassNotFoundException originally attached here looks more like if the sakila.ui.ActorComboBox was not compiled.

The real problem is that the sakila.ui.ActorComboBox actually initializes whole Hibernate and tries to read from the database. This is fine when the app runs standalone (though not sure if reading database from class static block is generally a good idea), but in design time this code gets executed in the GUI builder, i.e. inside the NetBeans IDE when it tries to load and instantiate the component class. I'm afraid Hibernate is not designed to work this way. It relies on thread context class loader which should load both the hibernate classes and also the config files (hibernate.cfg.xml). It would be possible to make the classes be loaded by the NetBeans context class loader, which would eliminate the mentioned ClassCastException, but this classloader can't find the hibernate.cfg.xml, which is part of the user project (note there can be multiple user projects). We can't give hibernate the right context class loader it needs inside NetBeans - we might try to fiddle with that but it would be fragile and unreliable from principle.

From my point of view Hibernate is simply not designed to run in custom components individually instantiated inside a GUI builder tool. I'd suggest to surround the code in ActorComboBox that initializes the Hibernate with if (!Beans.isDesignTime()) { ... }, so this code is not executed inside GUI builder, but otherwise the component should be usable. Would this be sufficient for you?

(Note if on JDK 7 newer than u21 you'll probably need to wait for fix of bug 234032 to propagate so the Beans.isDesignTime() check actually works.)
Comment 16 Quality Engineering 2013-08-09 10:49:38 UTC
Integrated into 'main-silver', will be available in build *201308090746* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/2e20c8a4ea34
User: Tomas Pavek <tpavek@netbeans.org>
Log: allow to exclude packages/classes in class loading specifications (found useful when playing with #231916)
Comment 17 bolsover 2013-08-09 11:40:41 UTC
(In reply to comment #15)
> Are you sure this worked before? Same as mentioned by Sergey I can't open the
> BrokenForm in 7.3(.1) either. I'm getting:
> 
> java.lang.ExceptionInInitializerError
>   at sakila.util.HibernateUtil.<clinit>(HibernateUtil.java:30)
>   at sakila.ui.ActorComboBox.<clinit>(ActorComboBox.java:26)
>   at java.lang.Class.forName0(Native Method)
> ...
> 
> caused by a ClassCastException logged as:
> org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
>   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
> ...
> 
> Note this is not related to whether I have the right database or not, here it
> fails to read the hibernate.cfg.xml file.
> 
> I'm getting this same exception from NB 7.3 as well as from current dev 7.4.
> 
> The (part of) ClassNotFoundException originally attached here looks more like
> if the sakila.ui.ActorComboBox was not compiled.
> 
> The real problem is that the sakila.ui.ActorComboBox actually initializes whole
> Hibernate and tries to read from the database. This is fine when the app runs
> standalone (though not sure if reading database from class static block is
> generally a good idea), but in design time this code gets executed in the GUI
> builder, i.e. inside the NetBeans IDE when it tries to load and instantiate the
> component class. I'm afraid Hibernate is not designed to work this way. It
> relies on thread context class loader which should load both the hibernate
> classes and also the config files (hibernate.cfg.xml). It would be possible to
> make the classes be loaded by the NetBeans context class loader, which would
> eliminate the mentioned ClassCastException, but this classloader can't find the
> hibernate.cfg.xml, which is part of the user project (note there can be
> multiple user projects). We can't give hibernate the right context class loader
> it needs inside NetBeans - we might try to fiddle with that but it would be
> fragile and unreliable from principle.
> 
> From my point of view Hibernate is simply not designed to run in custom
> components individually instantiated inside a GUI builder tool. I'd suggest to
> surround the code in ActorComboBox that initializes the Hibernate with if
> (!Beans.isDesignTime()) { ... }, so this code is not executed inside GUI
> builder, but otherwise the component should be usable. Would this be sufficient
> for you?
> 
> (Note if on JDK 7 newer than u21 you'll probably need to wait for fix of bug
> 234032 to propagate so the Beans.isDesignTime() check actually works.)

I agree with your comments about hibernate not being designed to run like this - and I have since refactored a number of classes to eliminate the problem.