Pages

Sunday, April 19, 2020

ERROR : DefaultDispatcherErrorHandler Exception occurred during processing request: failed to lazily initialize a collection of role,could not initialize proxy - no Session

ERROR : DefaultDispatcherErrorHandler Exception occurred during processing request: failed to lazily initialize a collection of role: com.javaimplant.socialnetwork.model.User.friend, could not initialize proxy - no Session
 org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.javaimplant.socialnetwork.model.User.friend, could not initialize proxy - no Session


I got this error while trying to map a One to Many relation in my Hibernate Entity.
The issue can be resolved by adding the following fetch property above our Entity Property.

 @OneToMany(fetch = FetchType.EAGER)  
      private Set<User> friend;  



Thursday, January 9, 2020

Autowire same bean using different Scopes in Class

Definitions in Application Context
      <bean id="RequestHit" class="com.springimplant.mvc.HitCounter" scope="request">  
           <aop:scoped-proxy/>  
      </bean>  
      <bean id="applicationHit" class="com.springimplant.mvc.HitCounter" scope="application">  
           <aop:scoped-proxy/>  
      </bean>  
      <bean id="sessionHit" class="com.springimplant.mvc.HitCounter" scope="session">  
           <aop:scoped-proxy/>  
      </bean>  
      <mvc:interceptors>  
           <mvc:interceptor>  
                <mvc:mapping path="/project/**"/>  
                <bean class="com.springimplant.mvc.interceptors.GlobalInterceptor"></bean>  
           </mvc:interceptor>  
      </mvc:interceptors>  

Defination in Class
 package com.springimplant.mvc.interceptors;  
 import java.util.Date;  
 import javax.annotation.Resource;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 import org.springframework.beans.factory.annotation.Autowired;  
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;  
 import com.springimplant.mvc.HitCounter;  
 public class GlobalInterceptor extends HandlerInterceptorAdapter {  
      @Resource   
      private HitCounter RequestHit;  
      @Resource  
      private HitCounter applicationHit;  
      @Resource  
      private HitCounter sessionHit;  
      @Override  
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  
                throws Exception {  
           RequestHit.setHits(RequestHit.getHits()+1);  
           System.out.println("Request Hits "+RequestHit.getHits());  
           applicationHit.setHits(applicationHit.getHits()+1);  
           System.out.println("Application Hits "+applicationHit.getHits());  
           sessionHit.setHits(sessionHit.getHits()+1);  
           System.out.println("Session Hits "+sessionHit.getHits());  
           request.setAttribute("currentDate",new Date());  
           return super.preHandle(request, response, handler);  
      }  
 }  

Wednesday, January 8, 2020

Autocomplete not working in spring bean configuration file

Project Properties > Spring > Bean Support > Config Sets > Add New Group (contains all configuration files). Then open applicationContext.xml again.

Monday, August 5, 2019

Guard access to outside world against your MySql Port

To Guard access to your Mysql Port from outside world just add following line to your my.ini file

bind-address=127.0.0.1

Thursday, August 1, 2019

The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path

The library referred to is bundled into an OS specific dll (tcnative-1.dll) loaded via JNI. It allows tomcat to use OS functionalities not provided in the Java Runtime (such as sendfile, epoll, OpenSSL, system status, etc.). Tomcat will run just fine without it, but for some use cases, it will be faster with the native libraries.
We can download the tcnative-1.dll (or libtcnative.so for Linux) and put it in the bin folder, and add a system property to the launch configuration of the tomcat server in eclipse.

Thursday, February 14, 2019

Load mnist dataset from a local file in jupyter

Recently while trying AI coding behind a proxy I was unable to load data from minist dataset from cloud.
So I manually downloaded the file "mnist.npz" kept it in {username}/.keras/datasets/ on my local machine and used the following command to load it

(X_train,y_train),(X_test,y_test)=mnist.load_data(path='mnist.npz');

And this block executed without any errors.

Monday, February 4, 2019

org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER will not be exported

I had the same issue after updating my JDK in project and resolved it by replacing my .classpath file with previous one. I noticed the following changes in my .classpath file
    
         name="maven.pomderived" value="true"/>
         name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    
The second line was missing from above code
 kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
This line was missing
     kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
    
         name="owner.project.facets" value="java"/>
    
These lines were added so I manually removed them and it all worked again.

Monday, November 12, 2018

The import javax.servlet cannot be resolved

This issue comes up when you change/upgrade the server currently running the application.
The fix is in your Java Build Path make sure the server runtime library is compatible with the server you are running your application on.


Saturday, June 16, 2018

Release port under use in windows

We will release port 8080 here which is being used by windows

The Error:

The Solution:

Let's first run the following commands in order
  1. netstat -a -o -n: This will provide us the process id of the process which is using the port.We find that process 4516 is using our port 8080 and we need to kill it.

     2. Next run the command taskkill /F /PID 4516 : This will kill the process.Make sure you have opened command prompt in administrative mode.

Wednesday, April 19, 2017

VMware Workstation unrecoverable error: (vcpu-0)

Trying to run OS X on a Virtual Machine and banging into following error.

VMware Workstation unrecoverable error: (vcpu-0)

vcpu-0:VERIFY vmcore/vmm/main/physMem_monitor.c:1180

A log file is available in "E:\temp\os x\vmware.log".  

You can request support.  

To collect data to submit to VMware support, choose "Collect Support Data" from the Help menu.

You can also run the "vm-support" script in the Workstation folder directly.

We will respond on the basis of your support entitlement.

Just add the following at the end of  VMX file(configuration file)

smc.version = "0"