radioAe6rt

On life with Hibernate, ORM, and free lunches

with one comment

My first experience with Hibernate came a few years ago while working with Oponia Networks. We used it to persist user account information and to query it accordingly. I recall quite well that it took a few weeks, a few books, and a policy of near complete sequestration from writing code to figure out how to configure the Hibernate entity mappings. A few weeks because the books have to be read carefully cover to cover, and because one does not approach any persistence layer lightly, and certainly not Hibernate or a JPA implementation in particular. These technologies require one’s full attention and ample soak time for the consequences and the unspoken to manifest themselves. And I’ve gotten back in the ring with these technologies as we attempt to rework the backend of taglets so that it can scale.

If you have programmed JDBC at the fine-grain that it requires, you never quite forget the first thrill of using Hibernate to persist an entity and its enveloped graph of objects. One fell
saveOrUpdate(entity) results in a glorious population of your database, and in the afterglow you do a few SQL selects in sheer admiration of what you’ve accomplished in so few lines of code. Cascade, OneToMany, ManyToOne, JoinTables, and on. It’s a small miracle it all even works, and everytime you lay eyes on the application code you are rather grateful it does.

But, alas, this is where the work just begins. Hibernate and JPA make it relatively easy to map entities and populate tables. But the fact that you’re using a database at all means you need to pay attention to transactions, boundaries, table locking, and scaling and performance. From the Ch. 9 introduction from Bauer and King’s Java Persistence with Hibernate (JPH): “In our experience, many developers are only really aware of the structural mismatch (Ed.: between object and relational systems) and rarely pay attention to the more dynamic behavioral aspects of the mismatch.” By dynamic behavioral aspects they mean everything that happens after the entity mappings are done: the runtime behavior of your system.

That single observation alone is enough to give one pause, because these guys are unusually good. If in their combined experience they state that most developers are not paying attention to things like transactions and “conversations” (database operations that naturally span user think-time) and object attached/detached state, then it seems to suggest that there are a lot of systems out there that either won’t scale or that just don’t do the right thing to begin with. To be fair to everyone involved, it is manifestly not always obvious at the outset of a project how to articulate what exactly the right thing to do is – that in itself takes time and learnings. And to continue reading JPH into the chapters on the persistence lifecycle, transactions and concurrency, and implementing conversations, it’s not hard to see why: these subjects are complex and subtle and they get that way fast.

The point is that once you choose to persist your data into any datastore that can be modified by more than one thread, things get hard. And that while these ORM tools are very cool, and very seductive, they solve some problems without saving us from the stuff that will always be hard. And in being seductive, they tempt you to forget that the hard stuff has to be dealt with. Like a loaded gun, it provides both an efficient path to dinner, and to a shot foot. Once the tables are mapped, the work has just begun.

Written by radioae6rt

February 5, 2010 at 1:37 pm

Posted in Uncategorized

Printing the default namespace in a Python minidom document

leave a comment »

Took me a while to find the solution to this: how to print an XML document with the default namespace using Python’s minidom:


from xml.dom import minidom

doc = minidom.Document()
rootElement = doc.createElement("root")
rootElement.setAttribute("xmlns", "http://foo.com")
doc.appendChild(rootElement)
print doc.toxml()

which outputs:

<?xml version="1.0" ?><root xmlns="http://foo.com"/>

If the rootElement.setAttribute() is omitted, no “xmlns” namespaceUri attribute will appear in the serialized output. Nor can one use doc.createElementNS(“http://foo.com”, “root”) in favor of the setAttribute() method. doc.createElementNS(…) alone is not sufficient to output the namespaceUri attribute.

Written by radioae6rt

January 16, 2010 at 4:30 pm

Posted in Uncategorized

Arithmetic in the bash shell

leave a comment »

I prefer scripting in bash vs. Perl when at all possible. When I got comfortable with bash arithmetic operations, it made choosing bash over Perl a lot easier in some situations.

Here’s a script that uses this simple arithmetic to count the total number of Java files in a directory tree as well as the total number of lines in that same file set:

#!/bin/bash

set -u

flist=files.txt

find . -name \*.java > $flist

((totalLines=0))
((totalFiles=0))
while read aFile; do
   ((thisLineCount=0))
   while read aLine; do
      ((thisLineCount=thisLineCount+1))
   done < $aFile
   ((totalLines=totalLines+thisLineCount))
   ((totalFiles=totalFiles+1))
   echo "$thisLineCount $aFile"
done < $flist

echo "total files: " $totalFiles
echo "total lines: " $totalLines


Bash also has “let” syntax that allows you an alternate way to signal that a variable is eligible for simple arithmetic operations (“let i=0″), but I find the equivalent double parentheses just easy to use and maybe a bit cleaner to read later.

Written by radioae6rt

July 29, 2009 at 8:30 am

Posted in Uncategorized

Taglets.org public API reference implementation

leave a comment »

We released an open source Java reference implementation for interacting with the taglets.org platform today. Java and Groovy developers, give it a whirl!

Written by radioae6rt

January 21, 2009 at 10:13 am

Posted in Uncategorized

Tagged with

Introducing taglets.org

with one comment

We are pleased to introduce the new site and service taglets.org. The service was cofounded by David Beckemeyer and I to explore tagging and tracking information on essentially any subject of which one can conceive.

The service is easy to use, with a more lengthy overview here. The short version: users create tags on objects (e.g., San Francisco BART or MUNI, your garage door sensor, iPhone development, The Genographic Project, and on and on.), then commence to post comments on those tags. Other users can “follow” that tag, which means that when comments are posted to the tag, they receive that comment in realtime via email, Twitter, or web service. By following a tag, you put yourself in the flow of information streaming from it. Anyone can post a comment to any tag, so the information on a tag accumulates and is made richer for its public accessibility.

The service is first a platform, with a reference implementation layered over it via the www.taglets.org web site, with the platform defined by a public API that developers can use to create and manage users, tags, and comments.

We thought the idea of following tags was interesting and potentially useful, and decided to implement it to see what such a service would look like. If you have feature requests or suggestions, please drop us a note at support@taglets.org.

Give it a try, and tell a friend. We think you’ll enjoy it.

Mark

taglets_logo

Written by radioae6rt

January 14, 2009 at 9:08 am

Posted in Internet

Tagged with

Using xmllint to format xml

leave a comment »

Long ago I used to use this utility with some frequency to pretty-print xml: xmllint, from the libxml2 project. I mention this here as much to remind myself how to use it as anything else.


$ export XMLLINT_INDENT=" "; xmllint --format foo.xml

where the environment variable XMLLINT_INDENT controls the indentation level. Two spaces are the default.

The utility is available without further ado on later versions of OS X, as well as on a number of Linux distributions, where I suspect it’s almost ubiquitous.

Written by radioae6rt

October 20, 2008 at 9:31 am

Posted in Internet

Tagged with

Configuring RESTlet’s via Spring

leave a comment »

After help provided by my friends on the restlet.org mailing list, I successfully configured my restlet-based app via Spring. The unrelated parts of the Spring bean config have been removed for the sake of brevity.

To use this config, get a reference to the “server” bean and invoke its “start” method to start the server. The server bean has wired into it the restlet/resource routing information, so there is no need to explicitly refer or otherwise show concern for the “router” bean at the application level.

The app has a number of resources, with associated routes, all of which are easily identified.

Written by radioae6rt

October 20, 2008 at 9:19 am

Posted in Internet

Morse Code practice utilities and files

leave a comment »

Jack Twilley has an excellent set of open source utilities for generating Morse code audio practice files. If you cannot put the source code to use, you can track the audio files he generates via RSS.

Written by radioae6rt

September 14, 2008 at 11:28 am

Posted in Internet

GWT-Restlet example app

leave a comment »

Rob Heittman posted a simple, standalone example of integrating Restlet technology into GWT apps. See the “Examples” section toward the end of the page.

Written by radioae6rt

September 11, 2008 at 5:09 pm

Posted in Internet

GWT-Restlet snippet

leave a comment »

Rob Heittman was good enough to post this tidbit of what a RESTful call and callback look like using the Restlet API in Google Web Toolkit:


 button.addClickListener(new ClickListener() {
    public void onClick(Widget sender) {
       new Client(Protocol.HTTP).put("http://localhost:8888/demo/hello.txt", "entity", new Callback() {
          @Override
          public void onEvent(Request request, Response response) {
              try {
                 label.setText(response.getEntity().getText());
              } catch (final Exception ioException) {
                  GWT.log("Restlet I/O failed", ioException);
              }
           }
        });
     }
   });

You’d use this in conjunction with a server process that can handle RESTful requests. A bit more detail can be found here.

Written by radioae6rt

September 10, 2008 at 10:15 am

Posted in Internet