Saturday, September 13, 2014

Unsolved agricultural engineering problems: Can today’s technologies solve them?

Agriculture being backbone of India today is still suffering from man power. Less farmers day by day and more demand for agricultural products.  Less people going for this occupation because farming is difficult and there are non-predictive yields. However there are examples where in people doing non agriculture job have shifted to agriculture but they are very few.   The very major reason is that agriculture in India has many problems unresolved. Agriculture requires lot of workers, so not much things are automated. I've tried to list down those. These problems might have been solved in other countries or specific reasons in India also but are not very popular in all India rural areas.

1. No proper machinery to harvest the maize. Though there exist the mechanized systems for harvesting the maize, they do not serve the exact purpose. For example, the maize harvesting machine (called Combine), crushes the entire maize plant which is unwanted. That means that it does reaping, threshing & winnowing at once. However, no effective husking machinery being used in India. Husking is very time consuming and requires huge hand power. Though there are husking machines talked about in the world, they not effectively used by India farmers. Due to this reason, farmers have decreased growing maize because harvesting it involves lot of manual work and requires huge man effort. The bottom line is that we need effective machinery for husking the maize.



Maize is one example crop whose cultivation problem is talked about, this is true for other crops as well such as rice, wheat etc.



2. Irrigation Management: No solution/system for managing the water pumping motor.   

Hence we do not have easy way to do the following.
Whenever there is power supply, the system has to notify user through message or call. When the system is configured to auto start the motor on power supply, the system has to do the same and inform user on the action.
The system has to auto stop the motor when the motor is not pumping the water and send alert on the same. When the motor is not pumping the water, it consumes less electricity which is below the minimum required to pump the water. The system should also receive start/stop commands through phone and execute the same.

3. What are the best yielding crops? There is no system for deciding which

crops to grow. Sometimes the farmers will be a dilemma as to which crops to plant. There has to be a system that measures the soil quality and suggests what can be cultivated. The system also takes other parameters into account before deciding such as the weather prediction for the year, season, amount of water availability etc. 


4. Lack of Best Market:  Sometimes farmers won’t get the right price for their agricultural (farm) products. There is no system for finding the brokers/agents who give the best price for their hard work.


5. Lack of Connectivity & collaboration: Though government has taken some steps such as agriculture toll free number for farmers to get information related to agricultural activities, it is not enough. The farmers need more  connectivity with other farmers, government agencies, agricultural universities and collaboration system to get maximum advantage. 


The above few problems might have given you some thoughts as to kind of the problems that the farmers face today. Again, these solutions may be already present in other agriculturally advanced countries and in some states in India itself. However, these solutions are not reaching all farmers. So the question remains, can today's technologies solve agricultural problems in India and reach out to all Indian farmers?

Tuesday, September 9, 2014

Hibernate Getting Started From Scratch In 3 Simple Steps

This is the quick starter guide to get started with hibernate  framework with Java in 3 simple steps using Eclipse IDE. The guide explains the steps required right from scratch in Windows platform. In short the hibernate framework is based on Java and Object Relation Mapping(ORM) tool which significantly reduces the work otherwise while dealing with relational databases using programming languages. It is assumed that the reader knows MySql and Java Programming Language basics, if not its recommended to learn them first. Please refer to the post for getting started with MySQL and JAVA.

1. Hibernate Installation

Download hibernate files from http://sourceforge.net/projects/hibernate/files/ the latest version at present is 4.x. You'll get zipped file called "hibernate-release-4.3.1.Final", unzip this into your local hard drive. Under the unzipped folder, there is lib\required folder which is the core of hibernate framework.

2. Create a Simple Java Project in Eclipse

You've created a database and Employee table in MySQL in the previous post. If not you need do that first. Add all the required hibernate jar files that you downloaded in the step1 to eclipse project build path.

2.1 Create a class called "Employee.java" which is a model class that is going to be mapped to Employee database table as shown below.



import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "employee")

public class Employee implements Serializable{
       private static final long serialVersionUID = 1L;
       @Id
       @GeneratedValue
       @Column (name="empid")
       private int empId;
      
       @Column(name="firstname")
       private String firstName;
      
       @Column (name="lastname")
       private String lastName;
      
       @Column (name="cubicle")
       private String cubile;

       public int getEmpId() {
              return empId;
       }
       public void setEmpId(int empId) {
              this.empId = empId;
       }
       public String getFirstName() {
              return firstName;
       }
       public void setFirstName(String firstName) {
              this.firstName = firstName;
       }
       public String getLastName() {
              return lastName;
       }
       public void setLastName(String lastName) {
              this.lastName = lastName;
       }
       public String getCubile() {
              return cubile;
       }
       public void setCubile(String cubile) {
              this.cubile = cubile;
       }
}


2.2 Create hibernate configuration file called hibernate.cfg.xml in source folder of your eclipse project with contents as shown below. This config file has information about connectivity driver, url, db credentials etc and importantly mappings from Java class to MySQL database table.


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydatabase</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">your_password</property>
<property name="hibernate.connection.pool_size">10</property>

    <property name="show_sql">true</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.current_session_context_class">thread</property>
   
    <mapping class="Employee"/>
   
    </session-factory>

</hibernate-configuration>

2.3 Create a utility class that creates hibernate session factory as shown below.


import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
       private static final SessionFactory sessionFactory;
       static{
              try{
                     Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
                     StandardServiceRegistryBuilder sb= new StandardServiceRegistryBuilder();
                     sb.applySettings(cfg.getProperties());
                     StandardServiceRegistry standardServiceRegistry = sb.build();
                     sessionFactory = cfg.buildSessionFactory(standardServiceRegistry);
              }catch(Throwable th){
                     System.out.println("Session factory creation failed...");
                     throw new ExceptionInInitializerError(th);
              }
       }

       public static SessionFactory getSessionFactory(){
              return sessionFactory;
       }
}

2.4 Now create HelloWorld Java program as shown below that uses the hibernate session factory, begins the transaction and displays contents from "Employee" table.

import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
public class HibernateHelloWorld {
       public static void main(String[] args) throws Exception{
              SessionFactory sessionFactory  = HibernateUtil.getSessionFactory();
              Session session = sessionFactory.getCurrentSession();
              org.hibernate.Transaction tr= session.beginTransaction();
              Query query = session.createQuery("from Employee");
              List list = query.list();
              for(Iterator i=list.iterator();i.hasNext();){
                     Employee employee = (Employee)i.next();
                     System.out.println("Employee name=="+ employee.getFirstName());
              }
              tr.commit();
              sessionFactory.close();
       }
}

3. Run HelloWorld Java program as Java Application and see the console for the result as shown below.

INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Sep 9, 2014 8:51:28 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select employee0_.empid as empid1_0_, employee0_.cubicle as cubicle2_0_, employee0_.firstname as firstnam3_0_, employee0_.lastname as lastname4_0_ from employee employee0_
Employee name==John
Related Posts Plugin for WordPress, Blogger...