Monday, October 17, 2011

OpenSource & RadioShack Myth

I like this quote by Larry (it's a bit old though, but very true)


"One of the myths of open-source is that it's built by a bunch of guys who work at RadioShack (a U.S. electronics store). And when they get home at night, they log on to the Internet and write codes," he said. "The largest investor of Linux with the most number of Linux engineers is from a little RadioShack-related company called IBM."


Read More....





Thursday, October 13, 2011

How to Autowire an argument to a constructor in Spring.

Look into this class:

public class SomeServiceImpl{


    @Autowired
    private AnotherService anotherService;


    public SomeServiceImpl(){
            doThisWithAnotherService();
    }


    private void doThisWithAnotherService(){
            anotherService.doThat();
    }
}


The above code will blowup while initilization with a NullPointerException inside the doThisWithAnotherService().  The reason being the constructor is called before AnotherService bean is injected.

Solution


public class SomeServiceImpl{


    private AnotherService anotherService;


    @Autowired
    public SomeServiceImpl(AnotherService aService){
        this.anotherService = aService;
        doThisWithAnotherService();
    }


    private void doThisWithAnotherService(){
        anotherService.doThat();
    }
}



Fields are injected right after construction of a bean before any config methods are invoked.

Source: http://static.springsource.org/spring/docs/2.5.x


Thursday, June 23, 2011

Error: Unable to transcode assets/xyz.png

I got this error while trying to build a Flex application using Apache ant and Flex 4.5 SDK (Got it even while directly using the MXML command). The strange thing is that, I was able to successfully compile this same project at my office using the very same SDK. I googled and nowhere did I get a satisfactory solution. There were so many threads and links which showed a similar problem:

 Error: unable to resolve 'assets/xyz.png'.

The fact is that, the above error is entirely different from the error I am talking about. The above error is just because the compiler can't resolve the image. A '/' or  '../' before the 'assets' will easily solve the above problem.

But the error:

Error: Unable to transcode assets/xyz.png

is different and frustrating. I happens even though that particular image could be resolved. 

After a few hours of research I finally figured out the problem. The problem was with the underlying JDK.

My Machine is using 64 bit Windows 7, and apparently the JDK  was also a 64 bit. Flex release notes doesn't mention that it supports 64 bit os and now it's clear -It doesn't support. Finally after switching to a 32 bit JDK the project got compiled successfully.

Note- if the above solution doesn't work, you should try downloading the latest 32 bit JDK and try. 


Wednesday, June 22, 2011

org.springframework.beans.FatalBeanException: Could not copy properties from source to target

I came across this irritating issue(While workign on a Spring based project).

org.springframework.beans.FatalBeanException: Could not copy properties from source to target; nested exception is java.lang.IllegalArgumentException: argument type mismatch
at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:599)
at org.springframework.beans.BeanUtils.copyProperties(BeanUtils.java:509)

Google took me to this bug which was already logged with SpringSource:

https://jira.springsource.org/browse/SPR-7693 (unfortunately it's still unfixed)

I made a quick fix/workaround for this.

Download/checkout : org.springframework.beans.BeanUtils.java

Add the below line after: writeMethod.invoke(target, value); (Around line 597) if using the 3.1 source.



if(logger.isDebugEnabled()){
logger.debug(MessageFormat.format("Source Property: {0}, Target Property:   {1}, Write method:{2}, Read Method {3} ", sourcePd.getName(),  targetPd.getName(), writeMethod.getName(), readMethod.getName()));
}

Add the file to your project. Now you can happily debug which property in the class is causing  problem.

Monday, June 20, 2011

Flex Builder 3 on Eclipse Ganymede

While this post might be obsolete, I believe its still useful.

I have had a problem this evening configuring Flex builder 3 with Eclipse. On the final step I was getting this annoying error and for that reason the installation fails:

Missing requirement: Flex Debug Plug-in for Eclipse 3.2 3.0.214193 (com.adobe.flexbuilder.debug.e32 3.0.214193) requires 'bundle org.eclipse.debug.ui [3.2.0,3.3.0)' but it could not be found.

The org.eclipse.debug.ui I have is much more higher version, so Flex shouldn't technically complain about this (3.5.x). I saw a lot of google posts asked by various users, but none had a solution. As I finally made it work, I thought it would be worth useful for somebody else out there.

Solution (Well precisely its not a solution, but a workaround)
  • Assuming you have already installed Flex builder.
  • Take a backup of : /com.adobe.flexbuilder.update.site/plugins/com.adobe.flexbuilder.debug.e32_3.0.214193.jar
  • unjar/open: com.adobe.flexbuilder.debug.e32_3.0.214193.jar
  • Edit META-INF/MANIFEST.MF
  • Remove the value : bundle-version="[3.2.0,3.3.0)" (which would be the last Require-Bundle section)
  • Update the Jar with the changes.
  • You might need to replace the modified com.adobe.flexbuilder.debug.e32_3.0.214193.jar into /plugins as well.
  • Restart and continue the flex update from eclipse.
This time the installation should pass. :)



Sunday, March 27, 2011

org.hibernate.util.JDBCExceptionReporter ORA-01407: cannot update (...) to NULL

I faced this issue for a while this afternoon while deleting a row which has a column referenced by a child table.



The cause for this is due to an incorrect JPA mapping:

Solution:
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_QUESTION_ID", updatable=false, insertable=false)

updatable=false - column is not included in SQL INSERT statements generated by the persistence provider.
updatable=false - column is not included in SQL UPDATE statements generated by the persistence provider.