|
I was looking for a java based persistence layer code and narrowed down my search to Torque, from the Apache DB Project.
Okay, so I downloaded it and attempted to run the example in the tutorial. After couple of hours of pulling my hair out, finally got it to work. Woo hoo!
If you are trying to go through the tutorial, save yourself some time! Apply these changes (errata) to the online tutorial and you should be up and running, certainly in a lot less time than it took me.
Read Step 1 online. Then apply these changes:
- It says "you need to obtain the Torque distribution", but there are more than one version available and it doesn't specify the version the tutorial was written for. I got the latest stable release, torque-3.0.2.zip from here.
Read Step 2 online. Then apply these changes:
- Under Torque Build Properties, it says "note: you'll need to add the torque.database.buildUrl property", but the sample code below it already has the specified property and also has a working default. So you can ignore the note.
- Under Torque Database Schema, it asks you to edit the project-schema.xml file located in the torque/schema directory. There is no such file in the distribution! Just make a new file and populate it with the sample code provided.
- Under Torque Run-Time Properties, it asks you to edit the torque.properties file in the torque/schema directory and make it look like the sample provided in that section. There is no such file! Even if you created one at that location, the example program which follows will not use it! Save yourself the trouble and make the following changes to torque/torque.properties, which is present:
torque.dsfactory.bookstore.connection.url = jdbc:mysql://127.0.0.1/bookstore
torque.dsfactory.bookstore.connection.user = dbusername
torque.dsfactory.bookstore.connection.password = dbpassword
Read Step 3 online. Then apply these changes:
- Under Generating the Object Model and Associated SQL, the ant -f build-torque.xml command will generate an error if you are behind a firewall and have to go through a proxy to access the internet. I haven't figured out how to solve this problem, but I think it would involve making sure the ant process gets the java properties http.proxyHost and http.proxyPort correctly configured. I didn't have this problem on my home machine and got the rest of the tutorial to work.
Read Step 4 online. Then apply these changes:
- The classes BookPeer.java, AuthorPeer.java and PublisherPeer.java have missing import statements for java.util.* (you may have already figured this out when you ran the ant -f build-torque.xml compile command). If you haven't done it yet, add those import statements.
That's it. If you still haven't got it running, try this trouble shooting. Still having problems, time to hit the mailing list.
Error
Running the sample application using java com.kazmier.Bookstore generates this error:
java.lang.NullPointerException: Connection object was null. This
could be due to a misconfiguration of the DataSourceFactory. Check the logs and
Torque.properties to better determine the cause.
at org.apache.torque.util.Transaction.rollback(Transaction.java:179)
at org.apache.torque.util.Transaction.safeRollback(Transaction.java:221)
at com.kazmier.om.BasePublisher.save(BasePublisher.java:512)
at com.kazmier.om.BasePublisher.save(BasePublisher.java:487)
at com.kazmier.Bookstore.main(Bookstore.java:26)
Cause
Step 3, torque.properties not set properly.
Posted by nmohideen
| TrackBack
|
|