OpenJPA, HSQLDB and proper shutdown

I’m starting to get tired of OpenJPA/HSQLDB setup that I’ve trying: it seems to give more problems than it solves. Now I discovered that the HSQL db wasn’t been properly shutdown and for reasons that I’m investigating, if the HSQL db is not propertly closed (SHUTDOWN command) it’s impossible to reopen it again. It fails with a IndexOutOfBoundsException. Caused by: org.hsqldb.HsqlException: error in script file line: 33 java.io.IOException: java.lang.IndexOutOfBoundsException in statement [SET TABLE PUBLIC.NOTES INDEX '2883070'] at org.hsqldb.Error.error(Error.java:111) at org.hsqldb.scriptio.ScriptReaderText.readDDL(ScriptReaderText.java:132) at org.hsqldb.scriptio.ScriptReaderBase.readAll(ScriptReaderBase.java:88) at org.hsqldb.persist.Log.processScript(Log.java:721) at org.hsqldb.persist.Log.open(Log.java:187) at org.hsqldb.persist.Logger.openPersistence(Logger.java:209) at org.hsqldb.Database.reopen(Database.java:265) at org.hsqldb.Database.open(Database.java:235) at org.hsqldb.DatabaseManager.getDatabase(DatabaseManager.java:222) at org.hsqldb.DatabaseManager.newSession(DatabaseManager.java:145) at org.hsqldb.jdbc.JDBCConnection.<init>(JDBCConnection.java:3219) ... 59 more Annoying. This is not OpenJPA fault, but it gets complicated to actually solve it. ...

January 14, 2010

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 Enhancer Ant task in a Netbeans project

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) <?xml version="1.0" encoding="UTF-8"?> <project name="JpaEntitiesLibrary" default="default" basedir="."> <description>Builds, tests, and runs the project JpaEntitiesLibrary.</description> <import file="nbproject/build-impl.xml"/> <target name="-post-compile"> <echo message="begin openJPAC"/> <path id="openjpa.path.id"> <pathelement location="${build.classes.dir}"/> <!-- Adding the OpenJPA jars into the classpath --> <fileset dir="C:\Users\ecerulm\Downloads\apache-openjpa-1.2.1-binary\apache-openjpa-1.2.1\lib" includes="*.jar"/> <!-- or if you create a OpenJPA Library you can use that instead --> <!--<pathelement path="${libs.OpenJPA.classpath}"/>--> </path> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask"> <classpath refid="openjpa.path.id"/> </taskdef> <openjpac> <classpath refid="openjpa.path.id"/> </openjpac> <echo message="end openJPAC"/> </target> </project> 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. ...

September 16, 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

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