Numeric null check on java server side failing with Flex BlazeDS AMF channel


One of the entities developed had a Numeric field as primary key, with a custom code to populate it rather than utilizing any auto generation strategy of JPA

if(ledegrHead.getLedgerHeadId()==null){
ledegrHead.setLedgerHeadId(financePersistence.getNextLedgerHeadId());
}

I wrote junit to test this and obviously it passed -if ID was set to null it would generate an ID.
But the moment I integrated it with flex, things went bad and it would NOT generate the expected “First” ID.
Reason - I had used autobinding on flex side -

[RemoteClass(alias="com.school.questionbank.Question")]
[Bindable]

This resulted in “auto” initialization of integer filed to zero and hence the condition of ==null would always fail. Solution? -explicit check for null as well as zero:

if(ledegrHead.getLedgerHeadId()==null||ledegrHead.getLedgerHeadId()<=0){
ledegrHead.setLedgerHeadId(financePersistence.getNextLedgerHeadId());
}

About ChandanPandey

Try to come up with a good design as by product of good coding practices

Posted on January 4, 2013, in Flex, Java and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: