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()); }
Posted on January 4, 2013, in Flex, Java and tagged AMF initialization, felx blazeds, null check. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0