Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate Persist a List Object in Hibernate
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Deepak Lal
Persist a List Object in Hibernate
1 Answer(s)      6 years and 2 months ago
Posted in : Hibernate



Advertisement
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


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
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
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
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
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 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
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
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
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 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
Hibernate 4 Supported Databases List
Hibernate 4 Supported Databases List In this tutorial you will learn that how... of databases. Here we are giving some of the Hibernate supported database list... you will be used in your application to persist the object you will have to use
How to get unique list in Hibernate using Criteria Query?
How to get unique list in Hibernate using Criteria Query?  Hi, Share me the example code for getting Unique List in Hibernate through Criteria Query? Thanks
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 Training
engine. How to persist different types of objects using the Hibernate... Hibernate Training        Hibernate Training Course Objectives
jpa one-to-many persist children with its ID
jpa one-to-many persist children with its ID  I have two tables like... persist the organization table it also persist to region . Here i Wont manually persist the region table how? any one help me
List
List  i do have one list object, i want to compare this list from database table and if match found i want to update the list
jpa one-to-many persist children with its ID
jpa one-to-many persist children with its ID  @Entity public class... can see from my annotaiton, When Item pesist, it will also persist its children... to change one-to-many's cascade persist behavoir, like persist Item first, then save
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
jpa one-to-many persist children with its ID by EntityListeners
jpa one-to-many persist children with its ID by EntityListeners  jpa one-to-many persist children with its ID by EntityListeners
List
List  getting values from a form and make a list of them and store them into database
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
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
JSP List Size
JSP List Size          JSP List Size is used to get the size of the list. The JSP List Size uses array list object to add the elements and finally
Insert an object with the add(Object) method
Insert an object with the add(Object) method       In this section you will learn to insert an object at the end of a list using the add(Object) method. Here is an example that provides
Hibernate 4
With Eclipse Hibernate Supported Databases List Hibernate <generator>... Hibernate update Method Hibernate persist Method Hibernate saveOrUpdate Method...Hibernate 4 Hibernate 4 is the latest version of Hibernate which was released
Complete Hibernate 4.0 Tutorial
. Complete Hibernate 4.0 Tutorial Hibernate is a Object-relational mapping...: Hibernate 4 Annotations Tutorial Given below the complete list of topics... List Hibernate <generator> Element Hibernate <generator>
hibernate
why hibernate?  why hibernate?   Hibernate: -Hibernate is an Open Source persistence technology. It provides Object/Relational mapping library. It solves object-relational impedance mismatch problems. Hibernate
Hibernate Code - Hibernate Interview Questions
Hibernate Code  This is the question asked in CAPEGEMINI Write a sample code how to persist inner class,interface,final class and how to invoke stored procedure in hibernate? From Surjeet
Hibernate Tutorials
by him on hibernate. Abstract: Hibernate is popular open source object... object/relational persistence and query service for Java. Hibernate lets you... Hibernate Tutorials       Deepak Kumar Deepak
Advertisements
 

 

 

DMCA.com