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


Java HibernateUtil类代码示例

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


HibernateUtil类属于com.pratik.utility包,在下文中一共展示了HibernateUtil类的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;
	//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

示例5: 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

示例6: main

import com.pratik.utility.HibernateUtil; //导入依赖的package包/类
public static void main(String[] args) 
{
	//use dao
			DAO_Interface dao=DAO_Factory.getInstance();
			//call getList method usung object collection
			List<Object[]> list=dao.getList();
			//display the list
						for(Object[]row:list) {
							for(Object val:row) {

									System.out.println(val);
								}
									System.out.println();
						}
		//close the session factory
						HibernateUtil.closeFactory();
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Native_SQL_Scalar_Using_DAO_Using_MAVEN,代码行数:18,代码来源:clientTest_Scalar.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: getList

import com.pratik.utility.HibernateUtil; //导入依赖的package包/类
@Override
public List<demo> getList() {
	//create the session
	Session ses=null;
	//get the session
	ses=HibernateUtil.getSession();
		//create the list of class object
		List<demo> list=null;
			//create the SQLquery
	SQLQuery query=ses.createSQLQuery("select * from product");
	query.addEntity(demo.class);
		//execute the query
		list=query.list();

			//close the session
		HibernateUtil.closeSession(ses);
		//return the list
		return list;
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Native_SQL_Using_DAO_Using_MAVEN,代码行数:20,代码来源:DAO_IMPL.java

示例10: 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

示例11: 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

示例12: 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

示例13: main

import com.pratik.utility.HibernateUtil; //导入依赖的package包/类
public static void main(String[] args) {
	OTM_DAO dao=null;
	//get DAO
	dao=OTM_DAOFactory.getInstance();
	//save objs
	dao.SaveDataUsingParents();

	
	//close objs
	HibernateUtil.closeSession();
	HibernateUtil.closeSessionFactory();
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_Maven_Set_OneToMany_FK_PK_Save_Load,代码行数:13,代码来源:OTM_Test_SaveData.java

示例14: main

import com.pratik.utility.HibernateUtil; //导入依赖的package包/类
public static void main(String[] args) {
	OTM_DAO dao=null;
	//get DAO
	dao=OTM_DAOFactory.getInstance();
	//save objs
	dao.loadDataUsingParent();
	
	//close objs
	HibernateUtil.closeSession();
	HibernateUtil.closeSessionFactory();
}
 
开发者ID:pratikdimble,项目名称:Hibernate_Association_Mapping_Maven_Set_OneToMany_FK_PK_Save_Load,代码行数:12,代码来源:OTM_Test_LoadData.java

示例15: main

import com.pratik.utility.HibernateUtil; //导入依赖的package包/类
public static void main(String[] args) {
	Session ses=null;
	//Query query=null;
	
	ses=HibernateUtil.getSession();
	Query query=ses.createQuery("from Emp");
	List<Emp> list=query.list();
	for(Emp e:list) {
	System.out.println("\n\t\t***"+e);
	}
   	HibernateUtil.closeSession(ses);
	HibernateUtil.closeFactory();
System.out.print("\n\t\t ==PROGRAMME BY PRATIK DIMBLE==\n\n\n");
}
 
开发者ID:pratikdimble,项目名称:Hibernate-Versioning_HQL_Maven,代码行数:15,代码来源:ClientApp_HQL.java


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