Persist a List Object in Hibernate

Persist a List Object in Hibernate

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
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
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
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.11 dependency
List of Version of com.persist>persist-json_2.11 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-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 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 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... gives you the list of Hibernate supported databases with the name of Dialect
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 - 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 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
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 Training
engine. How to persist different types of objects using the Hibernate...; Annotations for object/relational mapping with Hibernate Java... Hibernate Training       
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
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
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
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
Version of com.gingersoftware>object-csv_2.11 dependency
List of Version of com.gingersoftware>object-csv_2.11 dependency
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
ModuleNotFoundError: No module named 'persist'
ModuleNotFoundError: No module named 'persist'  Hi, My Python... 'persist' How to remove the ModuleNotFoundError: No module named 'persist... to install padas library. You can install persist python with following command
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
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
object of object class
object of object class  what do u mean by "object of object class
Artifacts of hibernate
List of Artifacts of hibernate maven depenency
Hibernate Tutorials
Hibernate Tutorials       Deepak Kumar Deepak... is a tutorial written by him on hibernate. Abstract: Hibernate is popular open source object relational mapping tool for Java platform. It provides powerful, ultra
Version of cn.danielw>fast-object-pool dependency
List of Version of cn.danielw>fast-object-pool dependency
Version of com.flipkart>hbase-object-mapper dependency
List of Version of com.flipkart>hbase-object-mapper dependency
Version of nanocontainer-hibernate>nanocontainer-hibernate dependency
List of Version of nanocontainer-hibernate>nanocontainer-hibernate dependency
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
ModuleNotFoundError: No module named 'persist-queue'
ModuleNotFoundError: No module named 'persist-queue'  Hi, My... 'persist-queue' How to remove the ModuleNotFoundError: No module named 'persist-queue' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'persist-wrapper'
ModuleNotFoundError: No module named 'persist-wrapper'  Hi, My... named 'persist-wrapper' How to remove the ModuleNotFoundError: No module named 'persist-wrapper' error? Thanks   Hi, In your python
Complete Hibernate 4.0 Tutorial
. Complete Hibernate 4.0 Tutorial Hibernate is a Object-relational mapping... tutorials: Hibernate 4 Annotations Tutorial Given below the complete list... Hibernate Supported Databases List Hibernate <generator> Element
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
Hibernate Tutorials
Hibernate Tutorials Hibernate is popular open source object relational mapping.... Hibernate is among the favourite object/relational persistence (ORM) tool... an object-oriented domain model to a conventional relational database. In addition
Hibernate 4
Hibernate 4 Example With Eclipse Hibernate Supported Databases List... 4 Annotation Example Hibernate update Method Hibernate persist Method...Hibernate 4 Hibernate 4 is the latest version of Hibernate which was released
Hibernate 3.1.2 Released
Hibernate 3.1.2 Released Back to Hibernate Tutorials Page Hibernate is a powerful, high performance object/relational persistence and query service. Hibernate lets you develop persistent classes following object-oriented
hibernate
hibernate  Is there any other way to call procedure in hibernate other than named query????? if we are using session object to get the connection then why hibernate we can directly call by using a simple java class??????? please

Ads