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"

Friday, September 30, 2016

Angular Js- Using minified version of Controller,filter js files

Using minifed version of controller JS Files

Here we will use a controller as an example same can be used for Filters

One important thing to note when we isolate controller from our HTML file is during its minification.
The minification also minifies variable in controller and $scope,$http,$filter may become variables a,b,c which are not recognized by angular see the minified version of above controller.js is as follows

controller.js

 angular.module('myApp',[]).controller('myCtrl',function($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 });  

controller.min.js

 angular.module("myApp",[]).controller("myCtrl",function(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]});  

Here $scope becomes n and this will not be recognized by angular js.To over come this problem use code controller code in controller.js as

controller.js

 angular.module('myApp',[]).controller('myCtrl',["$scope",myCtrl]);  
 function myCtrl($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 };  

In this we isolate the Controller function but we also tell the module that the first parameter of this function will be "$scope"

The Minified version of this file is

controller.min.js

 function myCtrl(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]}angular.module("myApp",[]).controller("myCtrl",["$scope",myCtrl]);  

Above file also changes the parameter $scope of the function to "n" but when final call is made to function the first parameter is sent as $scope

Monday, September 26, 2016

open cart 2.3 change Theme

To change in open cart 2.3

1. Go to Admin=>Extensions(main menu)=>Extensions(sub menu)




2. Select Themes as Extension Type

3. Click on Edit Action in Your store(blue button in above image) and select your theme directory


That's it

Saturday, September 24, 2016

Angular Js- Use a filter in expression with javascript addition operator

Recently in one of my Projects I was stuck up in an issue regarding filters

Here is My Custom Filter

       app.filter('alterCap',function()   
       {  
         return function(x)   
         {  
           var i, c, txt = "";  
           for (i = 0; i < x.length; i++) {  
             c = x[i];  
             if (i % 2 == 0) {  
               c = c.toUpperCase();  
             }  
             txt += c;  
           }  
           return txt;  
         };  
       });  

I am trying to use this filter in my HTML as

 {{ x.country|alterCap + ":" + x.capital|alterCap }}  

But this didn't worked out so I had to use filter in my controller.Here is how I did the same

 app.controller("myCtrl",function($scope,$filter){  
         $scope.capitals = [  
         {country:'India',capital:'Delhi'},  
         {country:'Sri Lanka',capital:'Colombo'},  
         {country:'Afganistan',capital:'Kabul'},  
         {country:'Bhutan',capital:'Norway'},  
         {country:'Nepal',capital:'Thimphu'},  
         {country:'Japan',capital:'Tokyo'},  
         {country:'China',capital:'Beijing'},  
         {country:'Russia',capital:'Moscow'},  
         {country:'USA',capital:'Washington, D.C.'}  
         ];  
         $scope.applyAlterCap = function(movie){  
           return $filter('alterCap')(movie);  
         };  
       });  

And then I used this in my Html as follows

 <p>Using Custom Filter with addition operator inside expression</p>  
     <ul>  
       <li ng-repeat="x in capitals | orderBy:'capital'">  
         {{ applyAlterCap(x.country) + ":" + x.capital }}  
       </li>  
     </ul>  

Tuesday, September 20, 2016

Ubuntu boots into command line after update

I recently faced this issue after updating to Ubuntu 15.10 and was looking for solutions until this one worked for me

Enter into recovery mode from grub and run the following  command

sudo dpkg --configure -a

Monday, January 4, 2016

Symfony-Error-Annotation not Imported

[Semantical Error] The annotation "@Template" in method AppBundle\Controller\DefaultController::indexAction() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /var/www/symfony_learn_2_6/src/AppBundle/Controller/ (which is being imported from "/var/www/symfony_learn_2_6/app/config/routing.yml"). 

Recently while working on symfony I encountered above error.The resolution is simple we just need to add Sensio annotation handler for the above annotation.So in this case since annotation handler for template is missing we need to add 

Sensio\Bundle\FrameworkExtraBundle\Configuration\Template

above the controller.Similerly if annotation handler for route is missing then we can add 

Sensio\Bundle\FrameworkExtraBundle\Configuration\Route

Sunday, December 27, 2015

Symfony-Generate Bundle Option not working in app/console

Recently in One of the symfony dumps I gathered from my IT team had an issue due to some reason "Generate Bundle" option was not working from app/console list -- raw

Solution :

Add following lines in File composer.json

"required-dev":{
"sensio/generator-bundle": "~2.3"
}

File AppKernal.php should have

new Sensio\Bundle\GeneratorBundle\SensioGenerator();

That's it

Thursday, July 30, 2015

Cakephp 2.0-Validations not working

Many a times Our custom Validations do not work in cakephp due to very tiny small errors.Here is a piece of my research and development which might help you
 In the controller
       if (!empty($this->data))   
       {  
         $this->User->set($this->data);  
         if ($this->User->validates())   
         {  
           // it validated logic  
           echo "Yes we can proceed";  
         }   
         else   
         {  
           // didn't validate logic  
           $errors = $this->User->validationErrors;  
           pr($errors);  
         }  
       }  

See the line in Bold this must be done to get errors set

In the view
   <?php   
       if($this->Form->isFieldError('User.username'))  
       {  
         echo $this->Form->error('User.username', null, array('class' => 'message'));   
       }  
       ?>  
Now set the class to taste and you will get error message in view in desired color.

Thursday, July 9, 2015

Cakephp 2.0-Adding favicon to your website

I was able to add a favicon to my website using code mentioned.This one is trusted and working.

 echo $this->Html->meta('favicon.ico','img/favicon.ico',array('type' => 'icon'));  

You need to place your favicon.ico file in/webroot/img directory

Sunday, April 5, 2015

Cakephp 3.0-Where IN Condition with list

So here comes Cakephp 3.0 with all new syntax new ORM and many other changes.I find myself struggling with Cakephp this hard since I used cakephp 1.3 for the first time.

But here is My first struggle to help you with

  return $this->find('list',['keyField' => 'id', 'valueField' => 'name'])->where([  
          'id IN'=>$nearCitys  
       ])->toArray();  

Saturday, April 4, 2015

Cakephp 3.0-Installing from Composer

Recently I was trying to install cakephp 3.0 from composer which was throwing some cache errors as such my install was unsuccessfull

Here is what I did to correct the same

When you run composer to install something let us suppose cakephp 3.0 it creates a cache in your home directory.In my case location was

/home/gaurav/.composer

 This location has a cache folder which works for composer installation.This is not writable by default so this should b provided write permissions also Cakephp 3.0 requires
  • mbstring extension
  • intl extension
which must be installed in advanced(google it to get concerned installation repository for your distribution)

After that my Install went smooth.