Netbeans & woodstox: ClassCastException: JAXBContextImpl cannot be cast to JAXBContext

Are you getting a ClassCastException in a Netbeans Platform Application, when you are you sure that the class can be casted? Then check http://wiki.netbeans.org/PlainView.jsp?page=DevFaqModuleCCE. This is most likely the result of the the classes being loaded by different classloaders. So JAXBContextImpl cannot be cast to JAXBContext because that JAXBContext is from Classloader “A” and JAXBContextImpl can only be cast to JAXBContext from Classloader “B”. SEVERE [global] java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to javax.xml.bind.JAXBContext at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:145) at javax.xml.bind.ContextFinder.find(ContextFinder.java:277) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337) at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244) at com.rubenlaguna.en4j.mainmodule.ImportEvernoteFile.actionPerformed(ImportEvernoteFile.java:65) at org.openide.awt.AlwaysEnabledAction.actionPerformed(AlwaysEnabledAction.java:115) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.AbstractButton.doClick(AbstractButton.java:389) at com.apple.laf.ScreenMenuItem.actionPerformed(ScreenMenuItem.java:95) at java.awt.MenuItem.processActionEvent(MenuItem.java:627) at java.awt.MenuItem.processEvent(MenuItem.java:586) at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:317) at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:305) at java.awt.EventQueue.dispatchEvent(EventQueue.java:638) at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104) [catch] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) BUILD SUCCESSFUL (total time: 28 minutes 5 seconds) So this could happen for example if you have both woodstox in a Netbeans Library Wrapper module and you make you application dependent on ide11 ⇒ JAXB 2.1 Library . ...

September 28, 2009

Netbeans refuses to recognize persistence.xml (no visual editor)

If you create the persistence.xml manually in Windows the file will be created with CRLF line endings (windows style line endings), that will prevent Netbeans for recognizing- Netbeans will not recognize it as the special file it is and won’t be able to to open it with the special/custom visual editor. [/caption] I opened an bug report netbeans issue #172538. At the beginning, I thought the problem was due to different line ending CRLF vs LF issues, but as pointed out in the bug report the line ending has nothing to do with it. It’s just the IDE restart what is needed, no need to change the line endings. ...

September 18, 2009

OpenJPA: Generated SQL contains extra UPDATEs

I’m trying to use OpenJPA to insert some entries in the database and I’m getting a strange number of UPDATEs beside the INSERTs. I isolated the problem to the following snippet of code private void start() { EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistencexmltest1PU"); EntityManager em = emf.createEntityManager(); for (int i = 0; i < 10; i**) { em.getTransaction().begin(); MyEntity n =new MyEntity(); n.setValue(i); em.persist(n); em.getTransaction().commit(); } } The generated SQL looks like this: ...

September 18, 2009

Derby 10.5 "OFFSET/FETCH" and JPA

It seems that no current JPA implementation is able to paginate the result using Apache Derby 10.5 OFFSET/FETCH mechanism. So javax.persistence.Query setFirstResult and setMaxResults don’t really translate into proper pagination with “OFFSET/FETCH” TopLink/EclipseLink org.eclipse.persistence.platform.database.DerbyPlatform Hibernate org.hibernate.dialect.DerbyDialect OpenJPA. org.apache.openjpa.jdbc.sql.DerbyDictionary

September 11, 2009

STaX: OutOfMemoryError when parsing big files

Java 6 includes STaX , when I tried to parse a Evernote backup file with it, I got a OOME error. java.lang.OutOfMemoryError: Java heap space at com.sun.org.apache.xerces.internal.util.XMLStringBuffer.append(XMLStringBuffer.java:205) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.refresh(XMLDocumentScannerImpl.java:1520) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.invokeListeners(XMLEntityScanner.java:2070) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(XMLEntityScanner.java:486) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2679) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:548) at Googling a bit I found a bug report 6536111. It says that this should be fixed in 1.6.0_14. But I tried Sun 1.6.0_16 and no luck. I got the exact same thing. ...

August 25, 2009

JTable, Beans Binding and JPA pagination

In my previous post I talk about JTable and JPA pagination through a custom TableModel. Now working directly with TableModel is not want you want to do, you want to use Beans Bindings because it means less manual coding and a lot of help from the IDE (like Netbeans). With netbeans you can easily bind a JTable to the result list of JPA query. But if that Query returns thousands of rows it’s going to be slow or unfeasible. And if you try to use JPA pagination (with Query.setMaxResults()) then you end with a table that will only show a subset of the rows. ...

August 18, 2009

JTable and JPA Pagination through custom TableModel

I really want to talk about JTable, Beans Binding and JPA pagination but I think I need to write about JTable and JPA pagination first. So I will take the Beans binding stuff in another post. By the way, choose wisely your JPA Provider/DB Provider combination, as some combinations will not give you any real paginations at all. For example, neither OpenJPA, Hibernate or TopLink/EclipseLink seems to support Apache Derby pagination (OFFSET/FETCH). The example here uses Derby and TopLink which is a bad example because the JPA pagination doesn’t get translated to SQL command for pagination. So if you really want proper pagination you should use other combination like Hibernate JPA/HSQLDB. ...

August 17, 2009

CGLib, NetBeans Modules and class loaders

My first try at using CGLib from a Netbeans RCP ended up in a ClassNotFoundException for net.sf.cglib.proxy.Factory I had two modules, MainModule and cglib and MainModule was depending on cglib. And the following snippet was raising the ClassNotFoundException. Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(Graph.class); enhancer.setCallback(NoOp.INSTANCE); Graph g = (Graph) enhancer.create(new Class[]{FrameListener.class,InterpreterAbstraction.class},new Object[]{fl,ia}) ; As I later found out from Enhancer documentation and DevFaqClassLoaders it seems that Enhancer it taking the System class loader instead of taking the Module classloader. I explicitly set the classloader used by the Enhancer via the setClassLoader method and now it seems to work. ...

August 6, 2009

Adding support for opening dot files to GraphBrowser

I spent some time on GraphBrowser, starting off the project, the first step has been to add basic support for opeining Graphviz DOT files. There are already some pages on the net talking about how to add open file support for new file types in NetBeans. File Type Integration Tutorial So there is no need to explain how to do it in a detailed way. The first main step is to invoke New File Type wizard on the module (in my case MainModule) to add the basic files to support the file type. ...

July 22, 2009

GraphBrowser

I decided to start a small project trying to port the GUESS framework into Netbeans RCP. The plan is to replace the GUESS own graphical library with Netbeans Visual Library stuff and replace the GUESS Python like interpreter with something more along the lines of JSR 223 Scripting for the Java Platform. For the moment I created the project at kenai.

July 18, 2009