Saturday, February 28, 2009

JavaRebel Licensing change

I've been trying out JavaRebel for some time now. It works like a charm if you take into account its features/limitations while developing.

Now Zeroturnaround is changing it's pricing/licecing model . Until March 9 2009 you can still buy perpetual licences for $100. Those licenses will still be in effect after that date but you can not buy new perpetual licenses after that date. They will only offer annual licenses.

Since I still had'nt bought JavaRebel I just went out and did it. Now I am a owner of JavaRebel perpetual license and just hoping that Zeroturnaround will not do some kind of draconian licensing stunt. The perpetual license does include updates but they could just release a new product instead.


PS: Like me, Zeroturnaround is of Estonian origin. On pure technical merits I would call the innovation of JavaRebel on par with Skype . This is just an amazing product that the big ones (Sun/IBM/...) have omitted.

Saturday, February 21, 2009

Struts 2 Ajax with JSON plugin

Heurekaaa!

I've managed to get the Struts 2 JSON plugin working. Surprisingly the thing works out of the box. Just initialize all of the stuff that you have there in the howto and you have Ajax with JSON data-transport. I even managed to integrate the example right into my application.

Maybe I'll be more verbose on the subject next post but i'ts 2 AM and I've earned my sleep for today.


PS: While researching the subject I also found this very recent presentation about JSON/Bayeoux/Comet generally and the Weblogic "Comet" API.

Thursday, February 12, 2009

Copying Hibernate objects

Today I had to copy my data in a MySQL database. My application uses Spring/Hibernate. Basically I had some rows in a database in multiple tables with relations and needed to make a copy of those with some of the data modified in the process.

Well I am an "ex" PHP guy, so ofcourse the most straightforward way should be the correct way - shouldn't it! Lets see. Our application uses Hibernate with POJO-s and manages all the data on object level. And I don't want to designate all the fields of a row (=properties of the object) one by one when copying. So I should just:
1. query the object form DB
2. give the object a new identity (reset the ID-s of that object with new ones and/or clone the object ) .
3. modify the new object according to our requirements (assign new relations, set some relations null, ...)
4. insert the object back to DB
Should be easy ... well not quite.

Hibernate keeps track of my POJO-s in a draconian CIA way, not a straightforward PHP way :). When I nullify the ID-s Hibernate just changes the existing object and since it is the same object the DB will be UPDATE when executing em.merge() or em.persist() . So I relly needed to eather clone the object using the "cloneable" interface or detach the object and modify the detached object. I could detach the object by serializing it or closing the EntityManager session but both methods are a bit too cumbersome to me for this simple task. I just need a simple way to copy database rows, something like this:

Object new_obj=copy(old_obj); em.persist(new_obj); .

So here comes the Hibernate3BeanReplicator .It does all the dirty work and still leaves me in control of the copying process. Like this:


Hibernate3BeanReplicator r = new Hibernate3BeanReplicator(null, null, null);
Object o_obj_new = r.copy(o_obj);
o_obj_new.setSomeRelation(null);
o_obj_new.setSomeIntField(0);
o_obj_new.setID(null); // we need to nullify the ID so that Hibernate will treat the result as a new object not a detached instance of an existin object
em.persist(o_obj_new);