Posts

org.hibernate.HibernateException: No Session found for current thread

I am working one Spring MVC project in which I have integrated Spring with hibernate and most of the time, I use to get this error message while performing database operation .. org.hibernate.HibernateException: No Session found for current thread Reason : This is happening because I have missed declaring the transaction in my Spring Application. sessionFacory needs transaction to work. Solution : Define transaction manager in your Spring configuration file. Here is my spring-config.xml file : < bean id = "dataSource" class = "com.mchange.v2.c3p0.ComboPooledDataSource" > < property name = "driverClass" value = "${db.driverClassName}" /> < property name = "jdbcUrl" value = "jdbc:mysql://${db.host}:${db.port}/${db.name}" /> < property name = "user" value = "${db.username}" /> < property name = "password" valu...

How to install SVN Client on CENT OS 6

It is quite easy to install SVN Client using YUM command line manage utility on CENT OS 6. Install : # yum clean all # yum install subversion Verify Subversion :  # svn --version Thanks..!!!

How to generate JavaDoc jar using Maven

The maven-javadoc plugin can be used to generate a javadoc jar file, It uses JDK's javadoc.exe tools to generate javadocs, p ack in jar file and deploy along with your project. To add support of javadoc in your Maven, Just add 'maven-javadoc' plugin into your pom.xml file and specify goal as 'jar'. Example : <!-- Generates JAVADOC --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId> maven - javadoc - plugin </artifactId> <executions> <execution> <id>attach- javadocs </id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> Run it as mvn:install or mvn:package, It will generate javadoc and package it as a jar file. Reference: http://maven.apache.org/plugins/maven-javadoc-plugin/      

Introduction to Lambda Expression with Examples

Java 8 comes up with one great features called Lambda Expressions. It's first step to the functional programming. With Lambda expression we can treat functionality as method arguments i.e. you can pass a method as argument to another method. Previously we use to write anonymous class if we wanted to pass some method as argument to another method but with lambda expression, we can pass a plain method as argument. Lambda expressions is a anonymous function i.e. It has arguments, a body and return type. Syntax of Lambda Expression : (Argument(s)) → {Body} Eg : (int x, int y, int z) - > {return x+y+z}; (String msg) - > {System.out.println(msg);} () - > { return 100;} Structure of Lambda Expression : It can have zero, one or more number of parameters. For empty set of parameters, Empty parentheses are used. e.g () -> 100 Type of the passed parameter can be explicitly declared or can be taken from context. e.g. (int x) is same as (x). One...

How to download and save image from URL

The 'javax.imageio.ImageIO' is a handy class which provides lots of utility methods related to images processing in Java. Using this class we can read and write images into disk. In below example, We will see how to use 'javax.imageio.ImageIO' to read an image from URL and save it into different formats. import java.awt.image.BufferedImage; import java.io.File; import java.net.URL; import javax.imageio.ImageIO; /** * This class will download the image from the specified URL and download it in * different format. * * @author abdulwaheed18 @gmail.com * */ public class ImageDownloader { /** * @param args */ public static void main(String[] args ) { String imageUrl = "http://img.gettyimageslatam.com/public/userfiles/redesign/images/landing/home/img_entry_002.jpg" ; try { System. out .println( "Downloading Image..." ); URL url = new URL( imageUrl ); ...