当前位置: 首页>>代码示例>>Java>>正文


Java HibernateUtil.getSession方法代码示例

本文整理汇总了Java中com.pratik.utility.HibernateUtil.getSession方法的典型用法代码示例。如果您正苦于以下问题:Java HibernateUtil.getSession方法的具体用法?Java HibernateUtil.getSession怎么用?Java HibernateUtil.getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.pratik.utility.HibernateUtil的用法示例。


在下文中一共展示了HibernateUtil.getSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadDataUsingParent

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public void loadDataUsingParent() {
	Session ses=null;
	Query query=null;
	List<Department> list=null;
	List<Employee> emplist=null;
	
	//get Session
	ses=HibernateUtil.getSession();
	//create Query obj
	query=ses.createQuery("from Employee");
	//execute Query
	emplist=query.list();
	//process the Results
	for(Employee emp:emplist){
		System.out.println("Child---->"+emp);
		//get all childs of each parent
			Department dept=emp.getDept();
			System.out.println("Parent--->"+dept);
		/*for(PhoneNumber ph:childs){
			
		}//for
	*/
		}//for
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_ManyToOne_Save_Load_Maven,代码行数:26,代码来源:MTO_DAOImpl.java

示例2: loadDataUsingParent

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public void loadDataUsingParent() {
	Session ses=null;
	Query query=null;
	List<User> list=null;
	Set<PhoneNumber> childs=null;
	
	//get Session
	ses=HibernateUtil.getSession();
	//create Query obj
	query=ses.createQuery("from User");
	//execute Query
	list=query.list();
	//process the Results
	for(User user:list){
		System.out.println("parent---->"+user);
		//get all childs of each parent
		childs=user.getPhones();
		System.out.println(childs.size());
		for(PhoneNumber ph:childs){
			System.out.println("child--->"+ph);
		}//for
	
		}//for
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_Maven_Set_OneToMany_FK_PK_Save_Load,代码行数:26,代码来源:OTM_DAOImpl.java

示例3: main

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public static void main(String[] args) {

		Session ses = null;			//creating the session object
		Emp em = null;				
		Transaction tx = null;		//creating transaction object
		Scanner sc=new Scanner(System.in);		//creating scanner for user input

		ses = HibernateUtil.getSession();			//get the cgf,factory,session
		
			em = new Emp();		//creating the domain class object
			System.out.print("\n\t\tEnter the Account Holder Name: ");
			String name=sc.nextLine();
			System.out.print("\n\t\tEnter the Account Type: ");
			String type=sc.nextLine();
			System.out.print("\n\t\tEnter the Account Holder Balance: ");
			float bal=sc.nextFloat();
				
				em.setHoldername(name);
				em.setAcctype(type);
				em.setBalance(bal);
		try {
			tx = ses.beginTransaction();
			ses.save(em);
			tx.commit();
			System.out.println("object is saved  with account number: "+em.getAccno());
			//System.out.print("\n\t\tEnter the Account Holder Name: ");
		} catch (Exception e) {
			tx.rollback();

		}
		HibernateUtil.closeSession(ses);
    HibernateUtil.closeFactory();

		System.out.print("\n\t\t ==PROGRAMME BY PRATIK DIMBLE==\n\n\n");

	}
 
开发者ID:pratikdimble,项目名称:Hibernate-Versioning_HQL_Maven,代码行数:37,代码来源:ClientApp.java

示例4: main

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public static void main(String[] args) {
	Session ses=null;
	Insuarance_DAO dao=null;
	Insurance_DAO_IMPL impl=new Insurance_DAO_IMPL();
	//get the session
	HibernateUtil.getSession();
	//use DAO
	dao=Insurance_DAO_Factory.getInstance();
	try {
	dao.savedata();
	}catch (Exception e) {
		e.getMessage();
	}
	//System.out.println(new Insurance_DAO_IMPL().savedata());
	HibernateUtil.closeFactory();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_Inheritance_Mapping_Table_Per_Class_Hierarchy_Using_DAO_Using_Maven,代码行数:18,代码来源:TestApp_setdata.java

示例5: main

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public static void main(String[] args) {
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
	//create the HQL query
	Query query=ses.createQuery("select pname,quantity from"
				+ " prod where price>=:id");
		//set the parameter to query
 	int value=500;
 		query=query.setParameter("id",value);
	//execute the query
	
	List<Object[]> list=query.list();
	//display the result
	 	for(Object[] row:list)
	 	{
	 		System.out.println("\t"+row[0]+"\t"+row[1]);
		}

		//close the session and session factory
		HibernateUtil.closeSession(ses);
		HibernateUtil.closeFactory();
System.out.print("\n\t\t ==PROGRAMME BY PRATIK DIMBLE==\n\n\n");
}
 
开发者ID:pratikdimble,项目名称:Hibernate_HQL_Select_Queries_Specific,代码行数:25,代码来源:ClientApp_HQL_specific_multilple.java

示例6: loadDataUsingParent

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public void loadDataUsingParent() {
	Session ses=null;
	Query query=null;
	List<User> list=null;
	List<PhoneNumber> childs=null;
	
	//get Session
	ses=HibernateUtil.getSession();
	//create Query obj
	query=ses.createQuery("from User");
	//execute Query
	list=query.list();
	//process the Results
	for(User user:list){
		System.out.println("parent---->"+user);
		//get all childs of each parent
		childs=user.getPhones();
		System.out.println(childs.size());
		for(PhoneNumber ph:childs){
			System.out.println("child--->"+ph);
		}//for
	
		}//for
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_BAG_OneToMany_Save_Delete_Maven,代码行数:26,代码来源:OTM_DAOImpl.java

示例7: getList

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public List<Object[]> getList() {
	//create the session
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
		//create the list of class object
		List<Object[]> list=null;
		//create the named parameterised the query
		SQLQuery query=ses.createSQLQuery("select PRODID,PRODNAME from PRODUCT where price>:price");
		//pass the parameter to query
		query.setString("price", "500");
	//add scalar to query
	query.addScalar("PRODID", StandardBasicTypes.INTEGER);
	query.addScalar("PRODNAME", StandardBasicTypes.STRING);
		//execute the query
		list=query.list();
			//close the session
		HibernateUtil.closeSession(ses);
		//return the list
		return list;
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Native_SQL_Scalar_Using_DAO_Using_MAVEN,代码行数:23,代码来源:DAO_IMPL.java

示例8: loadDataUsingParent

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public void loadDataUsingParent() {
	Session ses=null;
	Query query=null;
	List<User> list=null;
	List<Map<String,PhoneNumber>> childs=null;
	
	//get Session
	ses=HibernateUtil.getSession();
	//create Query obj
	query=ses.createQuery("from User");
	//execute Query
	list=query.list();
	//process the Results
	for(User user:list){
		System.out.println("parent---->"+user);
		//get all childs of each parent
		childs=(List<Map<String, PhoneNumber>>) user.getPhones();
		//System.out.println(childs.size());
		for(Map<String, PhoneNumber> ph:childs){
			System.out.println("child--->"+ph);
		}//for
	
		}//for
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_MAP_OneToMany_Save_Delete_Maven,代码行数:26,代码来源:OTM_DAOImpl.java

示例9: getdata

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public List<person> getdata() {
	List<person> plist=null;
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
	//access the named query
	Query q=ses.getNamedQuery("select_All");
	//execute the QBC logic
	plist=q.list();
	//diaplsy the list
	plist.forEach(p->{
		System.out.println(p);
	});
	
	return null;
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Component_Mapping_Using_DAO_Using_Maven,代码行数:17,代码来源:DAO_Impl.java

示例10: getdataCondition

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public List<Object[]> getdataCondition() {
	List<Object[]> newlist=null;
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
		//access the named query
	Query q=ses.getNamedQuery("select_by_range");
	q.setParameter("salary", 50000f);
		//execute the query
	newlist=q.list();
	newlist.forEach(row->{
		for(Object val:row)
		{
			System.out.println("--->"+val);
		}
		System.out.println();
		
	});
	
	return null;
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Component_Mapping_Using_DAO_Using_Maven,代码行数:23,代码来源:DAO_Impl.java

示例11: SaveDataUsingParents

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public void SaveDataUsingParents() {
	Session ses=null;
	Department dept=null;
	Employee emp1=null,emp2=null;
	//get Session
	ses=HibernateUtil.getSession();
	
	//parent obj
	 dept=new Department();
	 dept.setDeptName("Management");
	//child objs
	 emp1=new Employee();
	 	emp1.setEname("Ganesh");
	 	emp1.setEsal(30000f);
	 emp2=new Employee();
	 	emp2.setEname("Sandip");
	 	emp2.setEsal(20000f);

	//set childs to parent
		emp1.setDept(dept);emp2.setDept(dept);

	//save objs (parent to child)
	Transaction tx=null;
	try{
	 tx=ses.beginTransaction();
	  int idval1=(Integer) ses.save(emp1);
	  int idval2=(Integer) ses.save(emp2);
	 tx.commit();
	 System.out.println("Objects are saved...."+idval1);
	 System.out.println("Objects are saved...."+idval2);
	  }//try
	  catch(Exception e){
	    tx.rollback();
	    }
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_ManyToOne_Save_Load_Maven,代码行数:37,代码来源:MTO_DAOImpl.java

示例12: addingNewChildToExistingParent

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
@Override
public void addingNewChildToExistingParent() {
	Session ses=null;
	Department dept=null;
	Employee emp=null;
	Transaction tx=null;
	//PhoneNumber ph3=null;
   //get Session
	ses=HibernateUtil.getSession();
	//Load parent object(Existing)
	dept=ses.get(Department.class,1001);
	//child objs
	 	emp=new Employee();
	 	emp.setEname("Amit");
	 	emp.setEsal(60000f);
	 	//set to existing dept
	 emp.setDept(dept);

	try{
		tx=ses.beginTransaction();
		 int idval=(Integer)ses.save(emp);
		tx.commit();
		System.out.println("new Employee is added to existing Department: "+idval);
	}//try
	catch(Exception e){
		tx.rollback();
	}
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_ManyToOne_Save_Load_Maven,代码行数:29,代码来源:MTO_DAOImpl.java

示例13: main

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public static void main(String[] args) {
	Insuarance_DAO dao=null;
	//get the session
	HibernateUtil.getSession();
	//use DAO
	dao=Insurance_DAO_Factory.getInstance();
	dao.getdata();
	HibernateUtil.closeFactory();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_Inheritance_Mapping_Table_Per_Sub_Class_XML_Using_DAO_Using_Maven,代码行数:11,代码来源:TestApp_getdata.java

示例14: main

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public static void main(String[] args) {
	Session ses=null;
	Insuarance_DAO dao=null;
	Insurance_DAO_IMPL impl=new Insurance_DAO_IMPL();
	//get the session
	HibernateUtil.getSession();
	//use DAO
	dao=Insurance_DAO_Factory.getInstance();
	dao.savedata();
	
	//System.out.println(new Insurance_DAO_IMPL().savedata());
	HibernateUtil.closeFactory();

}
 
开发者ID:pratikdimble,项目名称:Hibernate_Inheritance_Mapping_Table_Per_Sub_Class_XML_Using_DAO_Using_Maven,代码行数:15,代码来源:TestApp_setdata.java

示例15: main

import com.pratik.utility.HibernateUtil; //导入方法依赖的package包/类
public static void main(String[] args) {

		Session ses = null;			//creating the session object
		Transaction tx = null;		//creating transaction object
		Scanner sc=new Scanner(System.in);		//creating scanner for user input

		ses = HibernateUtil.getSession();			//get the cgf,factory,session
		
				//creating the domain class object
			System.out.print("\n\t\tEnter the Account Holder Number:");
			int no=sc.nextInt();
			float bal = 0;
			boolean flag=false;
				
				Object ob=ses.get(Emp.class.getName(),no);
				Emp e=(Emp)ob;
				if(ob!=null)
				{
					flag=true;
				System.out.println("\n\t\t"+e);
				System.out.println("\n\t\tTransactions Left: "+e.getVersion());
		try {
			tx = ses.beginTransaction();

				
			if (e.getVersion()>5)
			{
				System.out.println("\n\t\tNo Free Transactions");
			}
			
				System.out.print("\n\t\tEnter the Amount to Withdraw: ");
				int amt1=sc.nextInt();
				bal=e.getBalance()-(amt1);
			
			e.setBalance(bal);
			ses.update(e);
			tx.commit();
			System.out.println("\n\t\tWithdrawn Money: "+amt1);
			System.out.println("\n\t\tBalance: "+e.getBalance());
			if((5-e.getVersion())!=0)
			{			System.out.println("\n\t\tTransactions Left: "+(5-e.getVersion()));
			}else
			System.out.println("\t\tNo Free Transactions Available");
				

			} //try
			catch (HibernateException he) {
			System.out.println("\t\tRECORD NOT FOUND");
			tx.rollback();
			he.printStackTrace();
			flag=false;
		}//catch
		catch (Exception e3) {
			tx.rollback();
			e3.printStackTrace();
			flag=false;
		}//catch
		finally
		{
			try {
				
				ses.close();
				HibernateUtil.closeFactory();
				flag=false;
			}//catch
			catch (Exception e2) {
				e2.printStackTrace();
				flag=false;
			}//catch
		}//finally
		
				System.out.print("\n\t\t ==PROGRAMME BY PRATIK DIMBLE==\n\n\n");
	}//main
}
 
开发者ID:pratikdimble,项目名称:Hibernate-Versioning_HQL_Maven,代码行数:75,代码来源:ClientApp_withdraw.java


注:本文中的com.pratik.utility.HibernateUtil.getSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。