<span class='line'>java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to javax.xml.bind.JAXBContext
</span><span class='line'> at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:145)
</span><span class='line'> at javax.xml.bind.ContextFinder.find(ContextFinder.java:277)
</span><span class='line'> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
</span><span class='line'> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
</span><span class='line'> at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
</span><span class='line'> at com.rubenlaguna.en4j.mainmodule.ImportEvernoteFile.actionPerformed(ImportEvernoteFile.java:65)</span>
and you are using woodstox be sure to check the DevFaqModuleCCE. This could happen when you have Netbeans Platform Application with a module containing woodstox but also including JAXB 2.1 in the module dependencies for the application.
when trying to push changes to a git repository via HTTP.
This is probably because you are using an HTTP proxy to access the repo and that proxy doesn’t support WebDAVHTTP methods (especially PROPFIND). So when git issues a PROPFIND the http proxy answers back with a 500 Internal Server Error or something like that.
It seems that PROPFIND is absolutely required so if you can use git:// directly or use a HTTP proxy which supports PROPFIND. Then I think the only option left is try use CONNECT in the proxy.
INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 1, (int) 0, (null) null]
INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 2, (int) 1, (null) null]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 3, (int) 2, (null) null]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 2]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 4, (int) 3, (null) null]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 3]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 2]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 5, (int) 4, (null) null]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 3]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 4]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 2]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
INSERT INTO MYTABLE (ID, VALUE, CREATED) VALUES (?, ?, ?) [params=(int) 6, (int) 5, (null) null]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 3]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 4]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 2]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 5]
UPDATE MYTABLE SET CREATED = ? WHERE ID = ? [params=(null) null, (int) 1]
...
pay attention to the extra UPDATE statements after each INSERT, the number of extra @UPDATE@s grows as well. From zero @UPDATE@s after the first INSERT, one in the second, two in the third, and so on. I don’t need to say that this is of course really inefficient. I don’t know what is ultimate cause of this but this started when I added a @Temporal(TemporalType.TIMESTAMP) annotation to the entity class. And I can make it go away by calling EntityManager.clear() after each em.getTransaction().commit()
UPDATE: Ok I found a bug report stating that this behaviour is only observed when the entity classes are not enhanced. . So the best solution is use the enhancer. But it really doesn’t work for me, I still get the extra UPDATEs even with enhanced classes. So I’m stuck with the EntityManager.clear() for now.. If the class is PROPERLYENHANCED the problem goes away.
Check the logs (enable them with <property name="openjpa.Log" value="DefaultLevel=TRACE"/> in persistence.xml) and make sure that you don’t see any entry like
5968 persistencexmltest1PU INFO [main] openjpa.Enhance - Creating subclass for "[class com.rubenlaguna.MyEntity]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
If you see the Creating subclass for message means that the class wasn’t enhanced, as I read OpenJPA really need enhanced classes, un – enhanced are just for testing and trivial examples.+
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.
The workaround is easy: change the newline (also line break or end-of-line EOL) characters to Unix style (LF) with any utility. I used Cygwin’s dos2unix (dos2unix src/META-INF/persistence.xml) and then just restart the IDE. Unfortunately just closing and reopening the project containing the persistence.xml file won’t work you have to restart Netbeans.
In the build.xml of the project (likely this will be a Java Class Library project), override -post-compile or -pre-jar and invoke <openjpac/>. You will need to add the build/classes and the openjpa jars to <taskdef/> and <openjpac/>. The <openjpac/> will enhance all classes mentioned in persistence.xml (which has to be in the classpath)
<span class='line'><?xml version="1.0" encoding="UTF-8"?>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><project name="JpaEntitiesLibrary" default="default" basedir=".">
</span><span class='line'> <description>Builds, tests, and runs the project JpaEntitiesLibrary.</description>
</span><span class='line'> <import file="nbproject/build-impl.xml"/>
</span><span class='line'>
</span><span class='line'> <target name="-post-compile">
</span><span class='line'> <echo message="begin openJPAC"/>
</span><span class='line'> <path id="openjpa.path.id">
</span><span class='line'> <pathelement location="${build.classes.dir}"/>
</span><span class='line'>
</span><span class='line'> <!-- Adding the OpenJPA jars into the classpath -->
</span><span class='line'> <fileset dir="C:\Users\ecerulm\Downloads\apache-openjpa-1.2.1-binary\apache-openjpa-1.2.1\lib" includes="*.jar"/>
</span><span class='line'> <!-- or if you create a OpenJPA Library you can use that instead -->
</span><span class='line'> <!--<pathelement path="${libs.OpenJPA.classpath}"/>-->
</span><span class='line'> </path>
</span><span class='line'>
</span><span class='line'> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask">
</span><span class='line'> <classpath refid="openjpa.path.id"/>
</span><span class='line'> </taskdef>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'> <openjpac>
</span><span class='line'> <classpath refid="openjpa.path.id"/>
</span><span class='line'> </openjpac>
</span><span class='line'> <echo message="end openJPAC"/>
</span><span class='line'> </target>
</span><span class='line'>
</span><span class='line'></project></span>
You can refer to the OpenJPA jars by either a <fileset> with the file path to the OpenJPA directory or by refererring to a Netbeans Library instead. You can create a OpenJPA Library via Tools ⇒ Libraries ⇒ New Library and add all the jars to the Library. If you name the library “OpenJPA” then you can refer to its classpath with <pathelement path="${libs.OpenJPA.classpath}"/>. See the commented code in the build.xml above.
IMPORTANT+: You may be tempted to put the <path> and the <taskdef> outside the <target>. I strongly disencorage this. If you do so then you need to ensure that ./build/classes directory is there before <path> is evaluated otherwise openjpac will fail to locate the META-INF/persistence.xml. So when you do an ant clean, the build/classes is deleted. If you do a ant jar after the ant clean, the build/classes will not be picked up by path and it will fail with a
[openjpac] <openjpa-1.2.1-r752877:753278 fatal user error> org.apache.openjpa.u
til.MetaDataException: MetaDataFactory could not be configured (conf.newMetaData
FactoryInstance() returned null). This might mean that no configuration properti
es were found. Ensure that you have a META-INF/persistence.xml file, that it is
available in your classpath, or that the properties file you are using for confi
guration is available. If you are using Ant, please see the <properties> or <pro
pertiesFile> attributes of the task's nested <config> element. This can also occ
ur if your OpenJPA distribution jars are corrupt, or if your security policy is
overly strict.
[openjpac] at org.apache.openjpa.meta.MetaDataRepository.initializeMetaData
Factory(MetaDataRepository.java:1567)
Although you can ensure that build/classes is always there overriding -post-clean and creating it there with something like:
Then you will fall into a second problem: ${build.classes.dir} variable is not accesible outside the <target>. That variable is loaded through -init-project target. So you will be forced to use something like ./build/classes instead of a proper ${build.classes.dir}. So it’s better to define the task inside the target.
By the way, if you don’t set properly the classpath you will probably get an exception like this
<span class='line'>java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: com.rubenlaguna.jpaentities.Notes
</span><span class='line'> at serp.util.Strings.toClass(Strings.java:164)
</span><span class='line'> at serp.util.Strings.toClass(Strings.java:108)
</span><span class='line'> at serp.bytecode.BCClass.getType(BCClass.java:566)
</span><span class='line'> at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:249)
</span><span class='line'> at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4493)
</span><span class='line'> at org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:89)
</span><span class='line'> at org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
</span><span class='line'> at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
</span><span class='line'> at sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source)
</span><span class='line'> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
</span><span class='line'> at java.lang.reflect.Method.invoke(Method.java:597)
</span><span class='line'> at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
</span><span class='line'> at org.apache.tools.ant.Task.perform(Task.java:348)
</span><span class='line'> at org.apache.tools.ant.Target.execute(Target.java:357)
</span><span class='line'> at org.apache.tools.ant.Target.performTasks(Target.java:385)
</span><span class='line'> at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
</span><span class='line'> at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
</span><span class='line'> at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
</span><span class='line'> at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
</span><span class='line'> at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:278)
</span><span class='line'> at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:497)
</span><span class='line'> at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
</span><span class='line'>java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: com.rubenlaguna.jpaentities.Notes
</span><span class='line'> at serp.util.Strings.toClass(Strings.java:164)
</span><span class='line'> at serp.util.Strings.toClass(Strings.java:108)
</span><span class='line'> at serp.bytecode.BCClass.getType(BCClass.java:566)
</span><span class='line'> at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:249)
</span><span class='line'> at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4493)
</span><span class='line'> at org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:89)
</span><span class='line'> at org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
</span><span class='line'> at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
</span><span class='line'> at sun.reflect.GeneratedMethodAccessor75.invoke(Unknown Source)
</span><span class='line'> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
</span><span class='line'> at java.lang.reflect.Method.invoke(Method.java:597)
</span><span class='line'> at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
</span><span class='line'> at org.apache.tools.ant.Task.perform(Task.java:348)
</span><span class='line'> at org.apache.tools.ant.Target.execute(Target.java:357)
</span><span class='line'> at org.apache.tools.ant.Target.performTasks(Target.java:385)
</span><span class='line'> at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
</span><span class='line'> at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
</span><span class='line'> at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
</span><span class='line'> at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
</span><span class='line'> at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:278)
</span><span class='line'> at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:497)
</span><span class='line'> at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)</span>
To add it to my wordpress theme (which doesn’t have a top sidebar for widgets) I had to edit (Appearance ⇒ Editor) the header.php file and add the snippet I got from Google there, at just at the end of the header.php. So the search web element is show right after the banner and before the posts.
In my case the code is
.
<!-- Google search web element BEGIN-->
<div id="cse" style="width:100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function(){
new google.search.CustomSearchControl('partner-pub-6449419902780618:ybxd02gp4hx').draw('cse');
}, true);
</script>
<!-- Google search web element END-->
Java 6 includes STaX , when I tried to parse a Evernote backup file with it, I got a OOME error.
12345678910
1 2 3 4 5 6 7 8 9 10
<span class='line'>java.lang.OutOfMemoryError: Java heap space
</span><span class='line'> at com.sun.org.apache.xerces.internal.util.XMLStringBuffer.append(XMLStringBuffer.java:205)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.refresh(XMLDocumentScannerImpl.java:1520)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.invokeListeners(XMLEntityScanner.java:2070)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(XMLEntityScanner.java:486)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2679)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
</span><span class='line'> at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:548)
</span><span class='line'> at</span>
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.
By the way I get this error in both Windows Vista and Mac OS X 10.5.6.
So I decided to go and use WoodStox instead (which is also a STaX API implementation). I worked like a charm.
At the beginning I though I would need to put the woodstox jars in the endorsed dir (-Djava.endorsed.dirs=“xxx”) but actually it’s not necessary at all.
You just put the woodstox’s jars (stax2-api-3.0.1.jar,woodstox-core-lgpl-4.0.5.jar) in the classpath and that’s it. In my case I was using it in a Netbeans Platform Application (RCP) so I created a Netbeans Library Wrapper with the two jars in it and make my module depend on this new library wrapper.
The JARs use the Service Provider (SPI) feature of jar files to register themselves as an STaX implementation. No changes in the code, you still use the STaX interface to do the parsing but the WoodStox implementation will be used instead.
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 BeansBindings 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.
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.
The “trick” here is to avoid binding the Table to the the result list given by the Query.getResultList(). You can create a custom List that does the JPA pagination behind the curtains and bind the JTable to that List instead.
How is this different from doing a custom TableModel? custom TableModel, custom List sound like the same amount of work. Well, right is the same amount of work but if you use Beans Bindings you get a lot of help from the IDE to manipulate the JTable graphically, etc.
You can follow any of the existingtutorials to create JTables bound to JPA entities to get an idea of how Beans Binding work.
Now I’m going to modify the test aplication from my previous post to use Beans Bindings together with the JPA pagination.
I’m assuming that the Entity class Customers from the previous post is already there, and TopLink and derby jars are in the classpath.
Here are the steps to create a JTable bound via Beans Binding to a List backed by a JPAQuery:
Right-click on the project New ⇒ JFrame Form
Add the Table from the Palette to the JFrame
Now we can add the EntityManager and the Query. Instead of adding those manually by typing we can add them graphically. Right-click on the Other Components item on the Inspector Window and selecting Add from Palette ⇒ Java Persistence ⇒ Entity Manager
Now we can configure the EntityManager by selecting it in the Inspector window and changing the properties in the Properties windows.
In this case we change the persistenceUnit to “JTablePaginationJPAPU” .
Then we can add the Query to the form. Inspector ⇒ Other Components ⇒ Add from Palette ⇒ Java Persistence ⇒ Query
And then we configure the query by changing its name to getRowsQuery and changing the query property to “SELECT c FROM Customers c” and the entityManager to “entityManager1”:
Add a second query to the form to get the number of rows in the table. Call it getRowCount and set the entityManager to “entityManager1” and the query to “SELECT COUNT(c) FROM Customer c”
Now we need a Query List because that is what we will bind to the JTable. Again Inspector ⇒ Other Components ⇒ Add to Palette ⇒ Java Persistence ⇒ Query Result.
We could link the Query Result to the Query but we won’t do that because then we don’t get pagination. What we will do with the query result is to change the “Custom Creation Code” property to “getList()” a method call that we will implement later. We also change the “Type Parameters” property to <Customers> to let the IDE know the type of objects stored in the list so netbeans is able to make suggestions later when we bind the JTable to this list.
OK, now we’ll bind the result list object with the JTable. Right-click on the JTable and select Table Contents ⇒ Bound ⇒ Binding Source ⇒ list1 . list1 is the name of the ResultListJPA object in my case.
Now click on the Columns tab and Insert 3 new columns. Select the first one and change the Title to “Id Number” and select “id” in the expression combo box (it should appear as ${id}).
Do the same thing for the other 2 columns until you get something like this
Now the JTable is properly bound to the list and we can run the file. You can see in the screenshot that the JTable shows the contents of the database and it makes new queries to the database as you scroll through the JTable.
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.
To get a JTable showing data from a paginated JPA Query you need to create a Custom TableModel for the JTable like this one:
The getValueAt in this custom TableModel make use from a paginated (setMaxResults) JPA query that take 100 rows each time. The database contains 30000 rows but with this TableModel you won’t need to retrieve all of them to display the JTable. Only the rows that need to be shown will be retrieved.
To fully understand this custom TableModel I think it’s better to illustrate a full application so I’m going how to describe how to create an example application with netbeans:
First we need a database, I used Java DB. Go to Netbeans ⇒ Services. Right click on Java DB and select Start server.
p.
Create a database. database name “namesdb” username and password “nbuser”.
Connect to the newly created database
Execute command
download the following sql script to create a table and insert 30000 rows. And execute it in sql command window
Now we have a table with 30000 entries that we want to show in a JTable
Let’s create a project in netbeans. New project ⇒ Java ⇒ Java Application
Let’s create the JPA Entity class for the database. Select the project and click on New ⇒
In the wizard select the connection and the customers table
Create a Persistence Unit also and specify TopLink as provider
Now you have created the entity classes for Customers
Now we need to add the Java DB / Derby drivers to the project so TopLink is able to find the drive to connect to the database. Right-click on the project Properties ⇒ Libraries ⇒ Add Library and select or create a library for derby
Now we can create our GUI
New ⇒ JPanel Form. Type JTablePaginationExample as class name
Drop a JTable into the form from the Palette
Now let’s add a custom TableModel to this JTable. Switch to the Source view and add the following