Second life goes open source, second life goes Linux

As said in their web, Linden Labs has dual licensed their Second Life client both proprietary and GPL. But that isn’t everything: a new Linux client has been developed, so we all can enjoy the experience, and there are even people talking about using Mono as a scripting engine.

I have tried Second Life, and the least I can tell you is that it’s simply amazing. You can create objects and animate them writing scripts, perform all kind of actions (riding bikes, driving cars, talking, listening music, watching videos (ok, only through QuickTime in Windows), buying and selling objects, meeting people… in summary living a life. You should give it a try.
As a sample, I show you this picture, where my avatar is editing her motorcycle and seeing the source code of the script that drives it (click to enlarge):

Second Life script editing

Curious facts about Hibernate

Hibernate is a very useful framework to do Object-Relational mapping in Java. It saves a lot of time, gives the programmer a lot of flexibility and allows you to do amazing things like mapping object inheritance.

Nevertheless, it has some “strange” behaviours that, in my opinion, seem a bit courterintuitive. I’m going to tell you about the way Hibernate translates object relations into joins.

Let’s imagine we have the class Person, with attributes id and name, and the class Car, with attributes id and brand. Class Person has a one-to-one relationship with Car named car, and there’ll be persons who have a car, and persons who haven’t.
If we want to query about the cars each people have, the “intuitive” query would be this:

select, from Person p

And the “intuitive” result would be: (John, Car instance #1); (Peter, null); (Mary, Car instance #2), isn’t it?

It isn’t. The real thing is that Hibernate translates the HQL sencence to a SQL one that selects from Person and does an (inner) join with Car, in order to instantiate a Car with all its attribute values set up. As a consequence of that inner join, all the people having a null car are missing from the result.

Intuitive solution: force the outer join by hand

select,, c.brand from Person p left join c

Non intuitive (but valid) solution: use the required attributes directly

select,, from Person p

In this last query, I would expect a NullPointerException when the person has no car, since if there is no car, there is no attribute to evaluate, but the exception doesn’t get thrown, the problem doesn’t arise and you get the work done.

Quite strange, isn’t it?