Hibernate and TopLink

I've had a lot of trouble using TopLink with Tomcat. Most of the problems appeared to be related to foreign keys and reverse-engineering but, looking deeper, were caused by 'weavers' and classloading. TopLink intercepts calls to POJOs by generating dynamic proxy code then weave them by playing switcheroo at classloader level. This technique apparently has some conflicts with Tomcat's own way of loading classes, conflicts that I spent many hours chasing and resolving only to face more later before giving up. I haven't used OpenJPA but I've read elsewhere that it's even worse. I am sure they'll improve but, for now, stay way.

After giving up on TopLink, I tried Hibernate 3.3 and, despite a lot of initial head scratching, I am happy to report that it worked well without even a single problem. Hibernate's two downsides are that it needs a lot of third-party jars to get it working and that it's rather slow. But then I couldn't go far enough along with TopLink to even test performance so the downsides are bearable. I can always rewrite the DAO layer later using iBATIS or use JDBC directly. For now, ease of development matters the most.

JPA Rough Spots

While JPA is nice, here are some possible rough spots:
Some foreign key columns will confuse TopLink JPA provider off in LAZY fetch mode, causing TOPLINK-60 exception that complains mysteriously about a missing method. Apparently the cause is related to some complicted 'weaving' logic. Quick fix is to switch to EAGER for the offending column (use missing getter method name as hint) and deal with consequences later.
Uncommitted Persist
Persisted but not yet committed POJO instances don't really exist which could lead to problems when you reference them from other POJO instances. Fix is to fiddle with CascadeType settings. For example, if A and B are both new instances and A.b references B, then make sure A.b cascade type is set appropriately (i.e. CascadeType.ALL) then just persist A. Since A.b is set to cascade, persisting A will cause B to be inserted first then its surrogate primary key will be used to insert A. If A and B has a OneToMany relatiohship then you would use A.getB().add(b) instead of A.setB(b).
Frankly, I don't like all this behind-the-scene cascading business so I try to avoid using it whenever I can. But it's difficult to avoid during inserts as the only alternative I can see is  brute-forcing commit and fetch at each step and deal with rollback manually.

OPML and Namespace

Dave Winer asks XML experts: can we put a namespace declaration at the head of an OPML file without breaking processors? If breakage of not even a single existing OPML app is acceptable, then the question can't be answered without actually counting the number of apps that breaks. But this can't be done because not everyone is paying attention.
My best informed guess is that this change will break some apps. A downside of simplicity in XML-based data format is that simplicity could mislead developers into doing task-specific hand-parsing instead of using fully compliant XML parsers.
I think it's more relevant to ask whether his immediate need requires namespace support. Looking at his proposed change (add ownerId element in the head section), I think just adding the element as-is will break fewer OPML apps than doing it the standard way using XML namespace.
Standards are useful but not when it hurts more than helps.

Bruce Schneier on Scanbone Culture

In response to news of pirated copies of the last Harry Potter book appearing on BitTorrent, Bruce Schneier wrote:

Anyone fan-crazed enough to read digital photographs of the pages a few days before the real copy comes out is also someone who is going to buy a real copy. And anyone who will read the digital photographs instead of the real book would have borrowed a copy from a friend. My guess is that the publishers will lose zero sales, and that the pre-release will simply increase the press frenzy.

Sounds reasonable but reasons tend to crumble before adaptive ways of life and culture. Already, Asia has developed a sizable culture of photocopied books shared online. In Korea, photocopied books are called 스켄본 (Scanbone) and they have gone beyond BitTorrent and into private storage services. And it's irreleveant whether they are fans or not because shortcuts can easily become a way of life.


Peter Yared, ex CEO of ActiveGrid, came by my house today. We sat outside (great weather today) and talked about our common past, (NetDynamics) and common near term focus. We took turn demoing our stuff and talked about ways to help each other. I think he has a potential winner with wdgtbldr, his new venture for which he already got a decent seed funding lined up, if he executes right. I am funding my own but I think Other People's Money could add the right kind of motivation and urgency I need to execute.
As to what his startup is about, it's ugly name speaks for itself. ;-p 

Chording Keyboard for iPhone and Mac?

I've read that iPhone's virtual keyboard is not as bad as initially thought but I wonder if Apple will implement virtual version of Engelbart's 5-key chorded keyboard using multi-touch. If done right, users could just tap on the phone's glass surface with five fingers to type (fingers will have to be closer to each other due to lack of space but I don't see a major problem). I thought about hacking together a web-version but, according to iPhone developer docs, iPhone browser doesn't deliver multi-touch events to webapps.
For Macs, I think multi-touch mouse which Apple recently filed patent for might be used. 

Update Pings via EC2

I am not sure if I got the numbers right but, assuming constant load of 20K users (not realistic but what the heck) pinging the server every 5 seconds (did anyone send me roses? no? did anyone send me flowers? no? so on) with each ping weighing about 1K, around 10-20 terabytes of traffic per month would result which would cost around $3-5K/month.
Other option is to get 10 dedicated servers, each with 2T bandwidth/month budget and handling 2K concurrent users, would handle the traffic and load handily. At $200 per server per month, price tag is $2K/month, cheaper than EC2 but more manual labor is needed to scale up.
Considering that 20K concurrent users is in the ballpark of Second Life, I think these numbers are good but they are specific to my apps which is task-oriented. For presence-oriented apps like Pownce, numbers would be much worse because they would have massive number of simultaneous users, even at lower ping rate (60 seconds for Pownce I think).
BTW, I am notoriously bad with numbers. This post is a disguised attempt to uncross my eyes with readers' help. ;-p 

RightScale and Amazon EC2

I've been meaning to get some hands-on experience with Amazon's EC2 (yup, still in beta) and S3 but just couldn't find the attention span until I came across RightScale. Signing up for EC2 and S3 was a breezy one-minute process and I haven't yet dug deeply enough to encounter complications but RightScale is supposed to let me ease over them and launch new server instances like one would rubber duckies in a tub.

I'll have to see for myself but it's good to know that at least OpenAds guys are having good result using RightScale/EC2 combo to test OpenAds in a wide-array of configuration combos. It's admin console seemed a tad sluggish (I wonder if they are using AWS as well and whether this is a common characteristic of AWS-based sites?) but I was impressed with a wide array of AMI images I could launch with just a few button clicks.
Um, yes. I am dating OpenAds but it could easily turn out to be a one-night stand as usual. We'll see. ;-p

TwitterGram Flash Client?

While looking over TwitterGram web service doc, I read:

The ideal client for this service, it seems, is Flash, because it can do the MP3 recording and has XML-RPC support.

I am not sure if Dave knows this but Adobe crippled audio recording in Flash so that bits from microphone are always sent directly to server-side <strike>*without* compression</strike> using a proprietary codec (NellyMoser). This means server has to capture and encode the bits into MP3, not the client. Yes, high server load should be expected. And since bits are sent in RTMP stream, your backend choice is limited. Adobe is expensive. <a href="//osflash.org/red5" target="_blank">Red5</a> is java-based. I&apos;ve heard good things about <a href="//www.amfphp.org/" target="_blank">AMFPHP</a> although I am not sure how much work is needed to use it to record audio.
If I had the ears of those in charge of Flash roadmap at Adobe, I would whisper:
<ol><li>Enable client-side audio and video recording (MP3 + <a href="//www.speex.org/" target="_blank">Speex</a> or better to start with) </li><li>Add UDP-based notification listener support (<a href="//en.wikipedia.org/wiki/STUN" target="_blank">STUN</a> to punch out)</li></ol>

Sure, there will be issues but these two features will kick many doors down, enabling new web applications practical. What separates toys from tools is the difference between possible and practical.
Update: I thought the audio was a simple variation of WAV but apparently Adobe is using NellyMoser, a proprietary mono-channel codec optimized for real-time speech. I am not sure if it's better than Speex (I doubt it) but that doesn't matter until the format is documented and free license offered to Flash developers. Fugger.

Toyota Prius and Fireworks

I took my wife and son to Magnussen's Toyota of Palo Alto to test drive Prius this afternoon. I liked the white Prius we test drove but my wife wasn't that comfortable with the front view. If I had to pick on something, it would have to be the rear camara view which was disorientating. But overall, I liked the car.
It was when we sat down to negotiate that trouble began. Their numbers just didn't make much sense so I asked them to break them down. All I got was breakdown into more mysterious figures. I told them that I felt screwed by Honda last time yet Honda numbers were better than the numbers they were showing me. After a brief "let me talk to the boss" game, a short guy showed up and proceeded to explain why I shouldn't compare Honda to Toyota. Blah blah blah. I told him I didn't care about those things.
At that point, the guy just blew up on me, yelling at me that he wasn't interested in selling and that I should go buy a Honda instead. Me being me (I have a temper but it takes a while to accelerate), I just watched him yell and stomp away. Then my wife started yelling back and my son was looking rather disturbed. Wow. When I asked a stunned sales person who the asshole was, I was told that he ran the place. Mr. Magnussen himself? Nah. Probably more like Mr. Magnussen's Big Mistake.
I still like Prius and can heartily recommend it but I am afraid I can't recommend the Toyota dealership unless you like that kind of fireworks. Hmm. Maybe it was a July 4th special event or something.