Wednesday, June 13, 2012

JsonMappingException when serializing POJO reverse engineered using Hibernate, to JSON

We were working recently on a Java project with Hibernate as the ORM. We created the database and reverse engineered the entities to POJO using Hibernate (See how).

I am putting up a simple ER diagram to demonstrate the issue.

Each Item has a list of item details which are name/value pairs.



And we needed to serialize this object to JSON so we used Jackson. And when trying serialize we were confronted with an exception.

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: ItemDetail.item, no session or session was closed

Closely looking at the generated ItemDetail class I found that there was a Item defined there. 

   @ManyToOne(cascade={}, fetch=FetchType.LAZY)  
   @JoinColumn(name="item_id", unique=false, nullable=false, insertable=true, updatable=true)  
   public Item getItem() {  
     return this.item;  
   }  
   public void setItem(Item item) {  
     this.item = item;  
   }  

The first (stupid) thing I tried was to change to FetchType from LAZY to EAGER. which I thought would solve the problem.  However that resulted in a StackoverflowException because the serializer kept recursing and it would never reach the end.

 Exception in thread "main" org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: ItemDetail["item"])

The problem here is that Hibernate provides us a way to navigate back using the foreign key relationship where in this instance to get the parent Item that belongs to each ItemDetail. But Jackson did not like it!

The solution was VERY simple.

Simply inform the serializer to ignore such parent relationships. You can inform Jackson to leave it aside using @JsonIgnore (See all the annotations here).

   @ManyToOne(cascade={}, fetch=FetchType.LAZY)   
   @JoinColumn(name="item_id", unique=false, nullable=false, insertable=true, updatable=true)   
   @JsonIgnore  
   public Item getItem() {   
    return this.item;   
   }   

And Jackson did not try to serialize it and it worked just as expected!

Saturday, June 2, 2012

Setup and forget automated backup with Cobian + Your favorite cloud hosting app!

There are numerous file cloud syncing/backup tools available such Sugar Sync, Dropbox, SkyDrive, Box.net and Google Drive to name a few.



These tools helps you keep your files safe in the event of a disk failure, virus attack or any other destructive situation, automatically.

You add a file/folder to the "special" sync folder and all is backed up and synced or use "selective sync", a highly sought after feature implemented in most applications, to select which folder to be synced to the cloud.

Now this is all good. But there are times when you really don't want some files to be synced always, all the time. The perfect example is the Outlook PST file which stores all your emails. You want it to be backed up, but it's going to be a waste of bandwidth if each time an email arrives and your file starts syncing to the cloud. There maybe many other such files that need not be synced ASAP.

What you need is some way to specify WHEN exactly do you want the sync to happen. How awesome would it be if you can tell "Hey, backup this file/folder every hour, every 135 minutes, every week or every first Monday and Thursday" ?

Cobian Backup to the rescue! I was looking for a flexible backup solution and found a gem. Luis Cobian has created a wonderful piece of software. Kudos!

Download Cobian Backup version 11 (Code named Gravity) , the latest as of writing and install it. I am assuming you have your sync tool installed as well.

Once Cobian Backup is installed, in the "Task" menu, click "New Task" or alternatively press Ctrl + A to add a task.


Note the setting "Use Volume Shadow Copy". Using that option, you can be sure that your file can be backed even while it's locked by an application.

After that add a source which could be any file or folder that you want to backup. The destination should be your magic folder (Dropbox/SugarSync Magic Briefcase") or any folder setup to be selectively synced. You can have multiple sources and multiple destinations.



As you can scheduling is very advanced and will cater to almost any need.


There's compression + industry standard encryption too!


with filters!



 I unfortunately cannot go through all the features in Cobian backup due to the sheer size!

So the idea is to use Cobian Backup to backup your files to the synced folder and you have a bullet proof, automated backup!

Download Cobian Backup

Thursday, March 8, 2012

The new iPad : Resolutionary!

No it's not iPad 3 or iPad HD! It's the new "iPad". 

Nothing entirely innovative or NEW, but the spec bump beats most of the tablets out there!




So there's a reason after call Apple calls it resolutionary! The resolution of the retina screen is 2048 x 1536 pixels with a 264 pixels per inch!

Other notable features are the new processor and GPU that Apple calls A5X and it claims to be twice as fast and contains four times the graphical processing power than the Tegra 3. Goodbye Asus Transformer Prime? Probably. It's still dual core, though.

There's a new camera, a 5MP, obviously with 1080p recording and the front VGA camera is still present.

There's 4G LTE connectivity too!

With all the processing power, the battery life still seems to be par with the iPad 2!

The 16GB WiFi Only Model starts from $499. Go, pre-order!

More info on New iPad: The Third Generation article on Gizmodo.

Monday, March 5, 2012

Android Key Lime Pie to follow Jelly Beans!

Yesterday it was confirmed that Jelly Beans will follow Ice Cream Sandwich in the Android sweets related OS naming convention.

However, therage.com has uncovered what's next. I took a wild guess thinking it would be Kola Kubes but it's Key Lime Pie!



Image courtesy of http://kestrachern.net

Sunday, March 4, 2012

It's confirmed! Android 5.0 will be called Jelly Beans

It's been a while since we knew that the next version of Android (After ICS) would be called Jelly Beans. But now, Asus has confirmed it! Speaking to TechRadar, ASUS' Corporate Vice President Benson Lin has said


"Asus is very close to Google, so once they have Android 5.0 I think there will be a high possibility that we will be the first wave to offer the Jelly Bean update."


So the version number 5.0 indeed will be called Jelly Beans.

Also, placed in the middle of Google's private meeting area is a bowl of Jelly Beans!

  google jelly beans
(Image courtesy of theverge.com)

So what's next ? Kola Kubes ?

Information taken from GSMArena.

Monday, February 27, 2012

HTC announces the One Series at MWC

HTC announced the HTC One Series a while ago at MWC held in Barcelona. Four phones were officially announced namely, One X, One XL, One S, and One V.

Sorted by top to bottom specification wise, HTC One V is the smallest of 'em all.

HTC One V


One V runs 1GHz single core processor with 512MB RAM and packs Ice Cream Sandwich inside coupled with their proprietary Sense UI. The resolution is 480 x 800 pixels on a 3.7 inch screen.

See the HTC's One V Page website for more information.


HTC One S


One S packs dual core power clocked at 1.5 GHz with an Adreno 225 GPU. With 1GB of RAM and qHD resolution of 540 x 960 on a 4.3 inch screen, HTC One S takes pictures at 8MP resolution. According to the HTC website, HTC One S supports only microSIM.

See the HTC's One S Page website for more information.

HTC One XL


The XL lives up to the name! Almost similar to the One S but with a beastly 4.7 screen with a 720p resolution and supports LTE!



See the HTC's One XL Page website for more information.

HTC One X








This is the beast that's going to storm the world of Android! Gizmodo calls it the "The Most Exciting Android Phone to Date"

One X (reminds of me of Professor X) is packs serious power inside. When I say serious, it's quad core serious! This beast with such raw power and magnificence was called HTC Endeavor, HTC Supreme and HTC Edge before.

Running on a Nvidia Tegra 3 clocked at 1.5 GHz this phone boasts 1GB of RAM. One X is equipped with the same screen as the One XL.

All these phones run the HTC Sense UI on top of Ice Cream Sandwich (Android 4.0)

HTC One X vs HTC One XL


They look almost the same with One XL packing LTE connectivity which One X lacks. Also One X is running on a quad core while XL is limited to a dual core.

Super IPS LCD2


We are yet to here more information on the Super IPS LCD2 which is the screen technology used in One X and XL.

But  @PaulOBrien  says

"I have never seen a screen like the SLCD2 on the@htc One X. Totally blew me away, INSANE. Made my Galaxy Nexus look 10 years old."



Looks like it's some beauty!

Check HTC  and GSM Arena for more information

Sunday, February 26, 2012

Samsung Galaxy Beam - Presentation time!

Samsung just before the MWC has announced a new phone! With a projector!

According to GSMArena, "the projector uses a 15 lumens lamp that is capable of projecting a 50-inch wide high-definition image."



What is interesting is that Samsung already introduced a Galaxy Beam before in February 2010. It was called Samsung I8520 Galaxy Beam. However it's not as powerful as the new Galaxy Beam. See the comparison here.

Check the link below for more information.