WO/ProjectWonder/WOLips – Part 2
I just completed part 2 of the WO/Wonder/WOLips series. This episode introduces:
- Reusable components
- Importing files into your project
- DirectActions
- Modeling relationships
- Updating a db schema with Migrations
It should be in available in WebObjects Podcasts on iTunes, from the WOCommunity site, or direct from my .mac account here.
Resources
Source of the completed project.
As always, comments and suggestions welcome.
Awesome screencasts! I think you’ve single-handedly sucked me into WOLips with these (I used to make due with WOProject+EOModeler+WOBuilder).
Thank you Wolf, that’s very high praise indeed… My nefarious secret plan has been exposed!
I agree, David. These screencasts are really great. You make things obvious and clear and watching live refactoring of code as you move it from component to component or to session/direct action is increasing my understanding by leaps and bounds. Thanks again.
Just wanted to say THANKS! I found this very useful even though I consider my self quite experienced in WebObjects. π
Thanks David and Ricardo. I’m glad you’re finding the screencasts valuable.
David, this is great stuff for helping the newcomers to WO. Keep up the good work. Hopefully, someday, my mountainous workload will ease off so that I can get back blogging about WO again!
Kieran
Thanks Kieran!
I’ve found your blog posts very helpful, and with the rapid progress in the WO tools, it certainly would be nice to have you voice returned to the mix π
First, great screencasts Dave! Simply an invaluable resource for learning WO. And now to the questions. I’m following along with my own app, but in mine I’m creating my EO Model in a Wonder Framework. First, is there anything wrong with doing that? Next, my Properties file (which seems to be quite full in your demo project) is empty in my project. Should this be the case? Perhaps because I’m developing a Framework? Will I be able to use the migrations stuff (which I’ll admit I don’t fully understand yet) to create my database schema with an empty properties file?
Thanks,
Jeff
Jeff,
There is absolutely nothing wrong with creating your EOModel in a framework. In fact for anything beyond a trivial app, it is recommended. We have several project on the go right now that use ERMigrations and have the their models in a separate framework.
If you add the ERMigration specific entries to your Framework’s Properties file it should all just work.
;david
Me again Dave,
I tried adding the entries to the Framework Properties file, and then referenced the framework from a Hello world WonderApp. This didn’t cause the migration class to run. However, when I added the ERMigration entries to my application’s Properties file, it did run, but with the below error. It actually created my table in the database, but then the app crashed on the error. I’m using Frontbase btw. Any ideas why I might be getting the error?
CREATE TABLE _dbupdater(“lockowner” VARCHAR(100), “modelname” VARCHAR(100)NOT NULL, “updatelock” INTEGERNOT NULL, “version” INTEGERNOT NULL);
.
at er.extensions.migration.ERXJDBCMigrationLock._tryLock(ERXJDBCMigrationLock.java:132)
at er.extensions.migration.ERXJDBCMigrationLock.tryLock(ERXJDBCMigrationLock.java:58)
at er.extensions.migration.ERXMigrator$ERXMigrationAction.doPerform(ERXMigrator.java:372)
at er.extensions.ERXEOAccessUtilities$ChannelAction.perform(ERXEOAccessUtilities.java:1311)
at er.extensions.migration.ERXMigrator.migrateToLatest(ERXMigrator.java:173)
at er.extensions.ERXApplication.finishInitialization(ERXApplication.java:825)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.webobjects.foundation.NSSelector._safeInvokeMethod(NSSelector.java:122)
at com.webobjects.foundation.NSNotificationCenter$_Entry.invokeMethod(NSNotificationCenter.java:588)
at com.webobjects.foundation.NSNotificationCenter.postNotification(NSNotificationCenter.java:532)
at com.webobjects.foundation.NSNotificationCenter.postNotification(NSNotificationCenter.java:546)
at com.webobjects.appserver.WOApplication.run(WOApplication.java:1223)
at er.extensions.ERXApplication.run(ERXApplication.java:919)
at com.webobjects.appserver.WOApplication.main(WOApplication.java:547)
at er.extensions.ERXApplication.main(ERXApplication.java:397)
at com.netbrackets.app.Application.main(Application.java:10)
Caused by: java.sql.SQLException: Syntax error 61. Expected Identifier not found.
at com.frontbase.jdbc.FBJErrorMetaData.errorMessageAtIndex(FBJErrorMetaData.java:162)
at com.frontbase.jdbc.FBJErrorMetaData.getExceptionChain(FBJErrorMetaData.java:194)
at com.frontbase.jdbc.FBJStatement.checkMetaData(FBJStatement.java:472)
at com.frontbase.jdbc.FBJStatement.executeUpdate(FBJStatement.java:262)
at er.extensions.ERXJDBCUtilities.executeUpdateScript(ERXJDBCUtilities.java:525)
at er.extensions.ERXJDBCUtilities.executeUpdateScript(ERXJDBCUtilities.java:492)
at er.extensions.migration.ERXJDBCMigrationLock._tryLock(ERXJDBCMigrationLock.java:127)
… 18 more
The first line (and probably most important) of the exception is:
[2008-4-1 4:11:9 CDT] er.extensions.migration.ERXMigrationFailedException: Failed to create lock table. Try executing:
Thank you for taking the time to produce your screencasts. As a WO beginner I am struggling to get started. The information contained in the available beginner books is quite different to the development approaches that are currently being used. It is wonderful that you and others are willing to help others get started. I particularly like the interactive nature of learning by following a screencast.
I am having problems getting the WO/ProjectWonder/WOLips – Part 1 working. Before I start to ask the community for help, would it be possible to obtain a copy of a ‘working’ version of the project to test and compare with my project to help with debugging. I have tried for days and still cannot find the error in my code.
Allan
The Screencast is wonderful! I was able to replicate everything except because I use WO5.4 I had to switch to Frontbase instead of MySQL. Following everything you did I struggled with the SQL Statements – in your screencast they where not completly visible and this step did not work – Error in SQL -Statement.
…sword,c_username,c_group_id,id) VALUES (‘ΓΒdmin’,’User’,’jj’,’profjens’,’1′,’1′)” ); – After “user” I guessed but got errors.
I did put in everything manually and managed to get that working but I also tried to “downgrade” with migration and could not find a clue how to do that. Where is the magic switch?
Another thing is the properties file. All the options are to defined where?
In case you’re following along, my problem was I hadn’t added the Frontbase plugin as a referenced framework. Still can’t get migrations to work though, no I’m getting an SQL syntax error Length > max message.
Thanks for all of the comments guys! A couple of things:
There are known issues with WO 5.4 and ERMigrations. The API’s ERMigrations uses generates incorrect SQL. This is slated for a fix in the next release of WO.
I use MySQL, so if you have FrontBase specific questions, a better place would be the WebObjects or Wonder mailing lists.
I’ll try and post snapshots of the projects later today.
If you can make it, I highly recommend attending WOWODC this year. From the horses mouth and all that π
;david
Thanks Dave,
Just one more easy question. Since I’m using Frontbase I think I want to just turn off migrations, but I can figure out how. I re-commented out all the migrations stuff in my properties files, and even deleted my migrations class, but when I run it still tries to “migrate” and I get a migration error and project won’t start.
Thanks
Jeff
Weird Jeff,
Did you comment out the entries in your framework, and have you tried cleaning the project?
Yes to all of that, and yet it still wants to migrate. Here’s a little bit of what my logger spits out. My migration class is completely gone, and yet it still looks like it’s trying to run it. It eventually gets a Migration Failed error and dies…
Apr 01 21:33:39 netBrackets[54250] (ERXNSLogLog4jBridge.java:44) DEBUG NSLog – evaluateExpression:
Apr 01 21:33:39 netBrackets[54250] (ERXNSLogLog4jBridge.java:44) DEBUG NSLog – fetch canceled
Apr 01 21:33:39 netBrackets[54250] (ERXNSLogLog4jBridge.java:44) DEBUG NSLog – 1 row(s) processed
Apr 01 21:33:39 netBrackets[54250] (ERXMigrator.java:392) INFO er.extensions.migration.ERXMigrator – Upgrading netbracketsFW to version 0 with migration ‘com.netbracketsfw.migration.netBracketsFW0@d5fcfe’
Apr 01 21:33:39 netBrackets[54250] (ERXJDBCUtilities.java:523) INFO er.extensions.ERXJDBCUtilities – Executing CREATE TABLE “t_pool” (
“c_admin_msg” VARCHAR(255),
Ahh, I figured it out. I guess I had installed the framework somewhere along the line in Library/Frameworks, probably using the handy WOLips Ant Tools->Install. After deleting my installed Framework it no longer tries to migrate.
Just for posterity, since this is one of the only hits on Google, I thought that I’d mention that I came across this with both openbase and mysql using WebObjects 5.4.1. I updated to 5.4.3 and the problem has gone away, so anyone with a similar problem should upgrade (which is a somewhat tortuous process all by itself, but that’s another story…)
The reason migrations fail using Frontbase is that _dbupdater is not a legal table name. I’m off now to figure out if there’s a way to tell migrations to use a different value.
Correction – table names may have underscores in the leading position but they must be quoted. This works:
CREATE TABLE “_dbupdater”(lockowner VARCHAR(100), modelname VARCHAR(100) NOT NULL, updatelock INTEGER NOT NULL, version INTEGER NOT NULL);
… but this does not:
CREATE TABLE _dbupdater(lockowner VARCHAR(100), modelname VARCHAR(100) NOT NULL, updatelock INTEGER NOT NULL, version INTEGER NOT NULL);
Great tutorial, though I block when writing migration code for version 0 to 1.
It seems that the “alter table t_user add c_group_id” statement is failing, as the application is submiting “alter table t_user null c_goup_id …” instead.
Does any one have an idea ? I am using the latest version (21-12-2008) of Wonder. I have the latest MySQL Connector/J.
I am pretty new to the thing, I would like to have a pilot to show some alternative to my company.
Any help greatly appreciated !