Package com

Source Code of com.logic

package com;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;


public class logic
{
  public static void main(String s[])
  {
    System.out.println("logic");
    SessionFactory s1=new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
    Session session=s1.openSession();
    login l=new login();
/*    l.setusername("v");
    l.setpassword("t");
    l.setemail("vipul@gmail.com");
    l.setphonenumber("960261");
    Transaction t=session.beginTransaction();
    session.save(l);
    t.commit();
  */
    Criteria c1=session.createCriteria(login.class);
  //  c1.add(Restrictions.and(Restrictions.eq("id", new Integer(0)),Restrictions.like("username","vipul")));
  //  c1.addOrder(Order.desc("id"));
  //  c1.setProjection(Projections.property("username"));
  //  c1.setProjection(Projections.property("address"));
    ProjectionList p1=Projections.projectionList();
    p1.add(Projections.property("username"));
    p1.add(Projections.property("address"));
   
   
    c1.setProjection(p1);
   
    List l1 = (List) c1.list();
    Iterator i =l1.iterator();
    while(i.hasNext())
    {
      Object o[]=(Object [])i.next();
      System.out.println(o[0] + "==" + o[1]);
     
     
    //  String str=(String) i.next();
    //  System.out.println(str);
    /*
      Object o=i.next();
      login l11=(login)o;
      System.out.println(l11.getid());
      System.out.println(l11.getaddress());
      System.out.println(l11.getemail());
      System.out.println(l11.getpassword());
      System.out.println(l11.getphonenumber());
      System.out.println(l11.getusername());
    */
    }
    System.out.println("save");
   
    session.close();
    s1.close();
   
  }
}
TOP

Related Classes of com.logic

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.