Sunday, 16 August 2015

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

To fix this use this jar

http://commons.apache.org/logging/download_logging.cgi

Add to class path

Wednesday, 8 July 2015

Spring REST xml responce


Spring rest json responce

1) Create bean of JSON view resolver

<bean name="jsonTemplate" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>

2) Return this Json view from modelAndView controller

@RequestMapping(value = "/clients")
public String getAllClientsJSON(Model model) {

model.addAttribute("clients", getClientsCollection());
 return "jsonTemplate";

 }

//getClientsCollection() this meothod will have list of clients

Tuesday, 30 June 2015

how to call a constructor from another constructor in java

how to call a constructor from another constructor in java
Use this keyword to achieve this

public class FooConstructor
{
    private int x;

    public FooConstructor ()
    {
        this(1);
    }

    public FooConstructor (int x)
    {
        this.x = x;
    }
}

Monday, 11 May 2015

what are MVC advantages

what are MVC advantages>>
1) Clear architecture design
2) Easy to expand the architecture
3)Multiple view like  pdf, csv, json, xml


Saturday, 9 May 2015

Hibernate n+1 solution

Hibernate n+1 solution.
Hiberntae has n+1 problame to solve this we can use the
1) Join
2)Criteria query
========================================
Let say i have one "client " and many "product" relationship here is one to many we use but when we
try to fetch the client records it also fetch product records by default lazily.

<<<<We need to use this query for to resoled this pro blame>>>
-------------------------------------------------------------
"from Client client join fetch client.product Product"
-------------------------------------------------------------
<<<<<Hibernate will Gen rate SQL query like this.>>>>>
-------------------------------------------------------------
Select * From Client client Left Outer Join Product product ON product.product_id =client.product_id
-------------------------------------------------------------

Other way is to use Criteria Query
Criteria cr =session.createCriteria(Client.class);
cr.setFetchMode("product",FetchMode.EAGER);