toplink.target.database
property missing from the persistence.xml file. This was outlined in a useful blog TopLink JPA and HSQLDB Quirk.
Even after making these changes however, I still could not get toplink to properly create the tables. It turns out, I had several entity beans which had name fields defined as
unique=true
. This caused the UNIQUE
keyword to be written in the CREATE TABLE
statements by Toplink which appears to be an invalid syntax for the HSQLDB database. After removing this JPA constraint from the affected objects I was able to successfully create the tables and run my tests. I also had some minor refactoring to do in some SQL utilities to leverage the persistenceUnit configuration, but I was very impressed with the speed.
Overall, my test suite went from executing in approximately eighteen seconds down to just four. While eighteen seconds may not seem like a long time, it was sufficiently long to disrupt my work efficiency. I decided to retain my MySQL peristence unit (for occasional "live" DB testing), and have now configured two test targets in Eclipse which take a
org.javad.jpa.serviceName
environment variable to switch between the hsqldb
and toplink-test
persistence units.
The final activity I will have left to do, is to determine a way to reinsert the unique statements in my entity beans without have the SQL generated for HSQLDB. There are a few threads out there, so I should be able to come up with something.
Finally, here is my persistence unit configuration for the HSQLDB database:
<persistence-unit name="hsqldb" transaction-type="RESOURCE_LOCAL"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <class>org.javad.stamp.model.Album</class> <class>org.javad.stamp.model.CatalogueNumberReference</class> <class>org.javad.stamp.model.Category</class> <class>org.javad.stamp.model.Country</class> <class>org.javad.stamp.model.Stamp</class> <class>org.javad.stamp.model.StampCollection</class> <class>org.javad.model.ClassVersion</class> <class>org.javad.services.TestEntityWithIdentity</class> <properties> <property name="toplink.jdbc.user" value="sa"/> <property name="toplink.jdbc.password" value=""/> <!-- <property name="toplink.logging.level" value="FINEST"/> --> <property name="toplink.jdbc.url" value="jdbc:hsqldb:mem:."/> <property name="toplink.jdbc.driver" value="org.hsqldb.jdbcDriver"/> <property name="toplink.ddl-generation" value="create-tables"/> <property name="toplink.target-database" value="HSQL"/> </properties> </persistence-unit>
2 comments:
Jason,
You should try upgrading to EclipseLink from TopLink Essentials. I can't guarantee the problem with unique is resolved but that is where the developers are actively working. If the problem still exists please file a bug and we'll get it resolved for you.
Doug
Thanks for the comment. Since I am not particularly tied to a JPA implementation, I will look into it. To be honest I chose to use Toplink Essentials over Hibernate partially for the deployment ease (there are a lot less JARs to deal with).
Post a Comment