Friday, June 26, 2015

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" value="${db.password}" />
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
depends-on="provDB">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="PACKAGE_NAME" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${db.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>

<bean id="dao" class="DAO_IMPL_CLASS.DaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

and Add @Transactional annotation on your service function

@Override
@Transactional
public String saveConfiguration(...) {
daoImpl.saveConfiguration(configuration);
return "issue_resolved";
}

I guess, It can be useful to many prople.. Happy Coding..!!!

Friday, May 29, 2015

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..!!!

Friday, February 20, 2015

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, pack 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:



     

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...