Friday, August 29, 2008

left/right outer join in Hibernate

Hibernate is great, but while HQL automates a lot of SQL, sometimes you run into things you can do in SQL that are hard in HQL...

For example, I wanted to do a left outer join between two tables, but I don't understand how to set one-to-one or one-to-many relationships in the XML config files for Hibernate, and as of August 2008, I believe that there's no syntax for simply doing an outer join without editing config files.

Suppose I've got two tables, A and B, both of which are properly mapped in Hibernate, and I want to do an outer join on A.x and B.y. I'd write this:

List list=
session.createSQLQuery(
" select {a.*}, {b.*} " +
" from A as a " +
" left outer join B as b " +
" on (a.x = b.y) " +
" where a.x = b.y "
).addEntity("a", A.class).
addEntity("b", B.class).list();

Note that if there is no corresponding entry in B for an entry in A, Hibernate correctly gives you back null (i.e. it doesn't give you an instance of class B with all the fields set to null or default, you legitimately get back null in row[1] of that entry in list).

The {a.*} syntax is a placeholder and the addEntity() calls fill in the fields based on the mappings in Hibernate. This syntax is kind of awesome because I can write SQL queries but take advantage of a lot of the automation and simplification that Hibernate provides. And I can do this without actually understanding a lot of the more complex aspects of Hibernate's config files (not great in the long-run, of course, but great today!)

Wednesday, August 20, 2008

The Gospel of Judas

Until age 10, I lived in Quincy, an Irish-Catholic neighborhood south of Boston. My family wasn't particularly religious, but still I dutifully went to Sunday school, completed my first communion, and sporadically attended church. My nominally Catholic upbringing (inadvertently, I'm sure) taught me that the bible was akin to a magical book---ancient, thick, and thoroughly inaccessible, at least to mortals like myself. My Dad, who had a similar Catholic upbringing, jokes that remembers the bible being spoken about with such awe and reverence that he feared to open it lest ghosts fling themselves from the pages.

Imagine my surprise my sophomore year of college when I realized that I could take Steve Finley's "The Bible as Literature" course, where we would read the bible as a literary text. Since then, and especially since I have very little patience with people who cite chapter and verse to justify their (usually intolerant) anti-science or social conservative agendas, I've become fascinated with the bible, especially the New Testament, and its intriguing history.

Back in August, on my way to and from Baltimore to visit my Dad, I listened to an audiobook version of Bart Ehrman's "The Lost Gospel of Judas Iscariot", as read by Dennis Boutsikaris and Lew Grenville.

First some backstory: The Gospel of Judas was discovered in 1978 in Egypt, but did not find its way to scholars until around 2001. In the interim, the document spent time in a safety deposit box in Jersey and was put into a freezer to "protect" the text (of course this damaged the text further). The Gospel of Judas is a Gnostic text that tells the story of Judas as Jesus's closest disciple, and the only one who truly understood Jesus. In this document, Judas does Jesus a great service by betraying him to the authorities. It's such a radical re-telling of the story that it almost reminds me of Gregory MacGuire's alternate takes on well-known stories such as "Wicked".

I learned a number of fascinating things from the book:
  • The Gnostics were (arguably) Christians who believed that there were many more Gods and divine beings than merely the God of the Old Testament. In fact they believed that the God of the Old Testament is not the most powerful being, but rather a blood-thirsty, reckless being, and also a fool. For the Gnostics, this secret knowledge (Gnostic comes from the Greek work for knowledge), along with a divine spark (which some humans ave and some do not), allows us to transcend this material world of suffering. There's quite a lot more to it than that, but the main take-home point for me is that the Gnostics believed the God of the old-testament to be a blood-thirsty fool.
  • One way to look at the historical Jesus is that he was a first-century Jewish Apocalyptic prophet. What is an apocalyptic prophet? The apocalypticists believed they were living in dark times, with some dramatic event on the horizon coming to shake things up. Apocalypticism was in part a response to the observation that just, righteous, upstanding Jews suffered greatly, often in proportion to their righteousness. This contradicted the doctrine of the supremacy of the God of the Old Testament, who was not holding up his end of the bargain to protect his chosen people, and caused considerable re-interpretation and re-figuring of the Jewish tradition that eventually placed all of the suffering of the chosen people into a context: The end was near, and people would be judged. There is textual support for this view in Mark, the earliest gospel, especially Mark 9:1 where Jesus says: "Truly I say to you, there are some of those who are standing here who will not taste death until they see the kingdom of God after it has come with power". There are some people there right now who "will not taste death" implies the to be very, very near. There is other textual evidence supporting this view as well, but that verse stuck out most in my mind. There were also other first-century apocalyptic prophets, including John the Baptist, Thudas, as and someone referred to in Acts only as The Egyptian.
  • Ehrman sketches out a fascinating hypothetical scenario about what, exactly, Judas betrays to the authorities, since it's unlikely that the location of Jesus was that difficult to figure out. It goes something like this:
    • Mark notes that Jesus was tried for proclaiming himself to be the king of the Jews, though Jesus never publicly proclaims anything like this in Mark.
    • Considering that he raised a ruckus at the temple and that passover always had the potential for riots, it's possible that the established Jewish leaders wanted to get this charismatic upstart out of the way before riots or violence did break out, both to protect their own authority in the Jewish community and to keep the Roman authorities from swooping in to quash a perceived rebellion. But first they needed some plausible excuse to have Jesus arrested...
    • The Romans always dealt harshly with anyone proclaiming themselves to be a "king" of any kind, but Jesus never says so publicly. Thus what Judas may have betrayed to the authorities was Jesus's private proclamation that he would be the king of the Jews. The fact that Jesus meant that this would happen in a strictly metaphorical sense after some kind of divine apocalypse was too fine of a distinction for anyone to bother parsing.
    • If this scenario were true, it's possible that Judas meant to protect Jesus from harm during this tumultuous passover season. He figured they'd arrest him, quickly realize that he had no political aspirations, hold him until after things had calmed down, and then they could all get back to preaching in Galilee.
    • It's also possible that Judas betrayed Jesus because he, like the other uneducated and illiterate disciples, had been promised leadership over one of the tribes of Israel in the coming kingdom. When would his happen? Soon. When? Soon. How about now? Not now, soon. Maybe he just got sick of all of this apocalyptic talk and betrayed Jesus out of frustration that the coming apocalypse... simply never came.
  • You must treat each gospel as a separate work of art. Each Gospel has a very particular message; these are works of literature, each with its own agenda. They are not histories. For example, in Mark, none of the apostles understand who Jesus really is, they all abandon him in his time of greatest need, Jesus asks three times that he not have to endure crucifixion, speaks not a word during his crucifixion, and his last words on the cross are "My God, My God, why have you forsaken me?". The women who find him after his resurrection are so terrified that they run out of the cave screaming, telling no one what they have seen. This is radically different from Luke, writing years later, who portrays Jesus as all-knowing, confident and in command of each situation, who carries on a series of conversations during his crucifixion, and who dies at peace, knowing that he will be resurrected. It doesn't make sense to conflate these two narratives into one big meta-narrative.
In conclusion, I highly recommend Bart Ehrman's book about the Lost Gospel of Judas Iscariot for anyone interested in early Christianity, Gnosticism, or some brief insights into the historical Jesus. Ehrman has another book called "The Historical Jesus" which I will probably read next. I've already read "Misquoting Jesus", another Ehrman project that looks into the history of the texts that have come to be called the New Testament. I'll write about that sometime later.

Tuesday, August 12, 2008

There is no knowledge that is not power...

I'm an information junkie. I listen to lectures from The Teaching Company on my iPod on my weekly pilgrimage to Ithaca, I rarely miss a Friday News Roundup, and upon first moving to the splendid isolation of Hamilton, NY, tried for over a month to replace regular television with old episodes of CSpan Booknotes and the Sopranos on DVD. (The latter experiment, however noble, lasted from late August until a mid-October breakup, combined with the lack of anyplace within 25 miles where I could watch NFL games, finally drove me to Time Warner Cable.)

I should note that I also like to read, but I don't have all that much time these days, and listening to books or lectures on my iPod lets me combine educating myself with exercise, which is the ticket I hope to ride to a lean body and a fat brain. Check with me at age 40 and see if I'm still under 200 lbs...

Recently I've realized that apparently I come from a long line of information junkies.
My Nana was a total information junkie when I was little, only I didn't recognize it as such until recently. I have fond memories of riding around in the plush purple leather backseat of her Chrysler, slightly sick to my stomach from either the scent of Parliament cigarettes or her erratic use of the gas pedal, bombarded with the sounds of her favorite call-in talk show. I recall the jingle for re-financing services (USA Loans, 848 3006, 848 3006, home-owners, when you need a loooooooan!) more vividly than all of the programs... Well, all of the programs except the one about Roseanne Barr's crotch-grabbing rendition of the national anthem before a baseball game (yes, I'm ashamed that I remember that one)... But there was always some new something being discussed on the radio.

Looking back now, the call-in show host probably wasn't too insightful, the callers were probably not very sharp, and I probably wouldn't bother with the show these days. Heck, I can barely stand some of the callers to the Friday News Roundup on NPR... I'm seriously going to flip out if I hear one more person call to complain that "the media didn't pick up the story on [fill in a story about impeaching Bush]" or "why isn't Ron Paul getting more attention?" or my favorite, "why is the media always covering stupid things about the candidates, what about the issues" (which as often as not comes from someone who doesn't appear to understand "the issues" very well themselves). Don't get me wrong, I'm all for criticizing the media, for example for their frenzied excitement over wars and the corresponding war-induced ratings bump, and the major TV networks' willingness to trot out retired military personnel to provide an independent analysis of the Pentagon's handling of the war, even though some of those military analysts were looking for lucrative Pentagon contracts that could clearly jeopardize their independence. It's not that I'm against bashing the media, especially in the US... It's just that I'd like a more nuanced perspective than "I didn't see the issue I'm interested in covered on the nightly news tonight, so the media sucks".

Anyway, the point of this is that, although the talk show she listened to was not something I would listen to, Nana was an information junkie. She always had the radio going in the house as well as the car, and she was a pretty enthusiastic TV watcher, especially during baseball season (the poor woman lived from 1919 until 1998, one of a generation of Red Sox fans who never saw them win it all). She never listened to music in the car, except for Frank Snotrag (pronounced "Sa-not-rag" so as to cleverly pun, as only 8-year-olds can, on Sinatra). This seemed strange to me when I was little... Why didn't she listen to music? Even to bad music that I didn't like? What was soooooo interesting about people talking? (This reminds me of the time I switched her Frank Sinatra tape for Michael Jackson's Thriller, and then waited in vain for what seemed like months for her to finally play some of Old Blue Eyes.)

Now I too have followed in her footsteps and become an information junkie. Lectures from The Teaching Company and NPR podcasts aren't enough anymore; I've discovered UChannel, short for University Channel, on iTunes, which is a clearing-house of recorded lectures, so while I'm coding I can have something "light" playing in the background. I can't stop trying to soak up information!

I don't quite know why I'm so obsessed with information... I'd like to think of it as a life-long commitment to education, but I think there's something else going on as well. For example, I'm not an information whore by any means; in fact, I'm very picky about what I listen to. I like people who are extremely informed on whatever they're talking about. I like people who speak reasonably well. I gravitate towards science, economics, archeology, and history. I don't like generic "news" all that much because it never provides enough context. I'm definitely entertained by learning new things, and I especially love the "knowledge is power" aspect of this where I can know more about a subject and not be fooled into thinking that something (like negative campaigning) is much worse today than in the past (I don't think it's not worse, maybe less histrionic and more manipulative). I definitely don't like hearing horrible things, like the use of rape as a weapon of ethnic cleansing in Darfur, because I get depressed. I like reading the economist online, and I'd love to listen to the Economist, because then I'd get all the articles in a British accent, which is about as cool as you can get.

More thoughts on this later, I need to sleep.