Home Answers Viewqa Hibernate Persist a List Object in Hibernate

 
 


Deepak Lal
Persist a List Object in Hibernate
1 Answer(s)      4 years and 7 months ago
Posted 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 Pages:
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
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 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
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
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 Training
engine. How to persist different types of objects using the Hibernate... Hibernate Training        Hibernate Training Course Objectives
hibernate - Hibernate
Hibernate; import org.hibernate.Session; import org.hibernate.*; import...();){ Object[] row = (Object[]) it.next...|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined
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
Complete Hibernate 4.0 Tutorial
Complete Hibernate 4.0 Tutorial Hibernate is a Object-relational mapping (ORM... list of topics on Hibernate 4 : Introduction To Hibernate 4.0 What's New... Example With Eclipse Hibernate O/R Mapping Hibernate Supported Databases List
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
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
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
Hibernate code problem - Hibernate
Hibernate code problem  Hai, iam working on simple login application using hibernate in spring. I've used Spring dependency injection too.I struck at DAO(data access Object)layer while executing the select statement in HQL
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 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 Collection Mapping
Hibernate Collection Mapping In this tutorial you will learn about the collection mapping in Hibernate. Hibernate provides the facility to persist... of collection in Hibernate. To create an example I am using List. A list stores
Data Access Object
Creating Data Access Object (DAO) Design Pattern The Data Access Object.... It provides a technique to separate the object persistence and data access logic... interface to access data. The DAO given with application, uses hibernate to access
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
Hibernate Tutorial
concerned with the Java object that has to be persist. There are various of Java...Hibernate Tutorial This section contains the various aspects of Hibernate. Here we will read What is Hibernate, Features of Hibernate, Compatibility
Linked List
(); public Object getFirst(); public Object getNext(); public Object removeFromFront(); public Object removeFromBack (); public boolen isEmpty(); } The number in the following logical linked list represents Computer Number. 76(head) 98 54
hi - Hibernate
); } public List findByPassword(Object password) { return findByProperty(PASSWORD, password); } public List findByFirstname(Object firstname... List findByDateCreated(Object dateCreated) { return findByProperty(DATE
hibernate
hibernate  1.difference between lazy=true and lazy=false? 2.difference between merge() and update()? 3.what is detached object
Hibernate Architecture
and the database. Hibernate produces an object called persistence object...Hibernate Architecture In this tutorial you will learn about the Hibernate architecture. Here we will understand about the architecture of Hibernate using
HIBERNATE- BASICS
landscape. HIBERNATE is an ORM ( Object-Relational-Mapping) technology. It is an Open... for this. In BMP, the coder has to write the sql to persist the object in memory... HIBERNATE- BASICS  (R.S.Ramaswamy)- ( in 3 parts) (part-1) ( CMP
Hibernate Creating criteria instance
Hibernate Creating criteria instance In this section you will learn about the creating of criteria instance in Hibernate. An instance of Criteria is created.... In this example I have shown a list of Worker by their workerId, firstname, lastname
hibernate - Hibernate
hibernate  what is hibernate and how to make a pc hibernating?  Hi friend, Hibernate is based on object oriented concept like java... use collection,mapping. Some advanced features of Hibernate are : Object
Hibernate - Hibernate
one example   Hi mamatha, Hibernate 3.0, the latest Open Source... from Hibernet.org.Hibernate is a solution for object relational mapping... not understandable for anybody learning Hibernate. Hibernate provides a solution to map
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 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
bean object
java.util.*; public class Bean { public List dataList(){ ArrayList list=new...()){ list.add(rs.getString("name")); } } catch(Exception e){} return list...(); List list=p.dataList(); req.setAttribute("data", list
Delete database Table through hibernate and Spring
Delete database Table through hibernate and Spring  Hi, I am using Spring,Hibernate and Tapestry to save and also fetch data simultaneously from... userDao implementation * @param userDao : object (implementation of UserDao
Using sum() in hibernate criteria.
Using sum() in hibernate criteria.  How to calculate sum() in hibernate criteria by using projection?   You can calculate sum of any numeric value in hibernate criteria by using projection. Projection is an interface
on collection mapping - Hibernate
occur more than once. They are very inefficient. A list is an indexed bag. The index informs hibernate whether a particular in-memory object is the same one...on collection mapping  differences b/w collection mappings tags list
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
hibernate - Hibernate
hibernate  I have written the following program package Hibernate; import org.hibernate.Session; import org.hibernate.*; import...();){ Object[] row = (Object[]) it.next(); System.out.println("ID: " + row[0
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
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
Complete Hibernate 3.0 Tutorial
Hibernate 3.0. Hibernate is popular open source object relational mapping tool..., provides an elegant bridge between the object and relational worlds. Hibernate also... and Example queries. Hibernate is now the most popular object/relational mapping
Hibernate 4 Annotations
a metadata for mapping the Object and Relational table. In Hibernate to provide... a table to persist the data. If this annotation is not used by default Hibernate...Hibernate 4 Annotations In this tutorial you will learn about the use
composinte primary key in hibernate
from tha table using hql query. Whenever i call the list() on the Query object it returns a List of pojo class objects. But inside the List object it placed.... After doing hibernate reverse engineering, by default it has taken composite
Hibernate criteria count.
create Persistent class ?Hibernate uses the Plain Old Java Object (POJO) classes...Hibernate criteria count.  How do we count rows using criteria in hibernate?   Create hibernate configuration file (hibernate.cfg.xml
Hibernate Criteria And Or
Hibernate Criteria And Or The Hibernate Criteria And Or is same...); List list = criteria.list(); Criteria And operation Criteria criteria... expression = Restrictions.and(roll, name); criteria.add(expression); List list
Hibernate criteria sqlRestriction.
Hibernate criteria sqlRestriction. In this tutorial, we will introduce you...(Restrictions.sqlRestriction(" name like '%%'")); List lists = criteria.list...(Restrictions.sqlRestriction(" name like '%%'")); List lists
list - Java Interview Questions
) method of Interface List public boolean contains(Object o) Returns...list  Hi all Naturally in java a list will allow duplicates, but if i want the list which shouldn't allow duplicates then what should be the logic
Hibernate criteria to sql.
Hibernate criteria to sql. In this tutorial, you will see the use of sql...;, Hibernate.STRING)); List obList = criteria.list(); Iterator obIter = obList.iterator(); while (obIter.hasNext()) { StudentBean object
Hibernate criteria query using Max()
Hibernate criteria query using Max()  What is Hibernate criteria query using Max()?   You can find out maximum value in hibernate criteria... in ?org.hibernate.criterion?. For using Projection object in our Criteria, we have to call
Hibernate criteria query using Min().
Hibernate criteria query using Min().  How to find minimum value in Hibernate criteria query using Projection?   You can find out minimum value in hibernate criteria by using projection. Projection is an interface

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.