Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

Persist a List Object in Hibernate

Ads

 
 

Share on Google+Share on Google+

Deepak Lal
Persist a List Object in Hibernate
1 Answer(s)      8 years ago
Posted in : Hibernate
Ads
View Answers

November 10, 2008 at 7:07 AM


Hi friend,


package net.roseindia;

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

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

public class projectionExample {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

Session sess = null;
try{
SessionFactory sfact = new Configuration().configure().buildSessionFactory();
sess = sfact.openSession();
Criteria crit = sess.createCriteria(Product.class);
ProjectionList proList = Projections.projectionList();
proList.add(Projections.property("name"));
proList.add(Projections.property("price"));
crit.setProjection(proList);
List list = crit.list();
Iterator it = list.iterator();
if(!it.hasNext()){
System.out.println("No any data!");
}
else{
while(it.hasNext()){
Object[] row = (Object[])it.next();
for(int i = 0; i < row.length;i++){
System.out.print(row[i]);
System.out.println();
}
}
}
sess.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}

}

}


---------------------------------------

Visit for more information.

http://www.roseindia.net/hibernate/projections/hibernate-projections.shtml

Thanks

Ads









Related Tutorials/Questions & Answers:
Persist a List Object in Hibernate - Hibernate
Persist a List Object in Hibernate   Hi All, I have a query on hibernate. How to persist a List object in Hibernate ? Can you give me...(Projections.property("price")); crit.setProjection(proList); List list = crit.list
Hibernate persist Method
Hibernate persist Method In this tutorial you will learn about how to use persist method in hibernate. Hibernate's persist() method is used to insert... (primary key) value that is generated by the hibernate but the persist() method
Advertisements
object chaining? - Hibernate
object chaining?  daoobject.getsession().begainTransaction; can any one explain the code, i am not understanding this line when iam working with swt and hibernate
how to iterate hibernate object
how to iterate hibernate object  am just learning hibernate .by the hibernate am getting one list to display a grid(grid has 5 column). now i want to iterate one only column value to calculate total of that particular column. how
what is object chaining? - Hibernate
what is object chaining?   daoobject.getsession().begainTransaction; can any one explain the code, i am understanding this line when iam working with swt and hibernate
hibernate object states and life cycle
hibernate object states and life cycle  I am bit confused in between the hibernate states and it's life cycle. Can you please explain this also? also explain the persistent, detached and transient object states.Thanks
Version of com.persist>persist-json_2.10 dependency
List of Version of com.persist>persist-json_2.10 dependency
Version of com.persist>persist-json_2.12 dependency
List of Version of com.persist>persist-json_2.12 dependency
Version of com.persist>persist-json_2.9.2 dependency
List of Version of com.persist>persist-json_2.9.2 dependency
Version of com.persist>persist-logging_2.11 dependency
List of Version of com.persist>persist-logging_2.11 dependency
Version of com.persist>persist-json_2.11 dependency
List of Version of com.persist>persist-json_2.11 dependency
Version of com.persist>persist-logging_2.12 dependency
List of Version of com.persist>persist-logging_2.12 dependency
Hibernate dialects list
Hibernate dialects list  Can anyone share me the list of dialects of Hibernate? Thanks   Hi, Hibernate supports many databases with the help of Dialects. You can check the list of Hibernate dialects at the tutorial
Hibernate 4 Supported Databases List
Hibernate 4 Supported Databases List In this tutorial you will learn that how many databases are supported by Hibernate. You must be looking for the list... the list of Hibernate supported databases with the name of Dialect to be used
Hibernate Criteria Unique List Example
Hibernate Criteria Unique List Example   How to write Hibernate Criteria Unique List Example? I want example of Hibernate Criteria Unique List in Java. Thanks   Example of Hibernate Criteria Unique List. Check
Hibernate Criteria Unique List Example
Hibernate Criteria Unique List Example   Hello, I have just started to learn the Hibernate. I want example of Hibernate Criteria Unique List. Thanks   Example: Hibernate Criteria Unique List. Check the tutorial
save list of objects in Spring and hibernate
save list of objects in Spring and hibernate  I use a javascript which add dynamic rows with values in jsp. Now i want to save these multiple values using spring and hibernate. Thanks for help
Hibernate Criteria Unique List
Hibernate Criteria Unique List An example of hibernate criteria unique list is given below, which returns the unique value in list from a table... it will display message as shown below: Hibernate: select this_.roll
Calling hibernate query list() method generates errors
Calling hibernate query list() method generates errors  Hello, I'm trying to debug someone's codes. But I am not an expert of hibernate so I'm asking your help about this. I am trying to retrieve a list of jobs from
Hibernate criteria - how to use criteria to return only one element of an object instead the entire object.
Hibernate criteria - how to use criteria to return only one element of an object instead the entire object.  How to use criteria to return only one element of an object instead the entire object?   You can use
Hibernate Training
engine. How to persist different types of objects using the Hibernate... Hibernate Training        Hibernate Training Course Objectives
Version of hibernate>hibernate dependency
List of Version of hibernate>hibernate dependency
Version of hibernate>hibernate-tools-hibernate dependency
List of Version of hibernate>hibernate-tools-hibernate dependency
Video Tutorial: Hibernate 4 Supported Databases List
Hibernate 4 Supported Databases List Hibernate being an object relational... database. Hibernate also takes the initiative to solve the problems of object... databases. Here, the list of Hibernate 4 was compiled which supports the MySQL
Hibernate One to Many XML Mapping list Example
In this section, you will learn how to do one to many mapping using List to retain mapping order in Hibernate
Hibernate O/R Mapping
maps an object to the relational database table. Hibernate is also an O/RM...Hibernate O/R Mapping In this tutorial you will learn about the Hibernate O/RM (Object/Relational Mapping). O/RM itself can be defined as a software
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
Version of hibernate>hibernate-annotations dependency
List of Version of hibernate>hibernate-annotations dependency
Version of hibernate>hibernate-avalon dependency
List of Version of hibernate>hibernate-avalon dependency
Version of hibernate>hibernate-entitymanager dependency
List of Version of hibernate>hibernate-entitymanager dependency
Version of hibernate>hibernate-tools dependency
List of Version of hibernate>hibernate-tools dependency