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  
 

Retrieve data using Criteria api

Ads

 
 

Share on Google+Share on Google+

Pintu Ranjan Sai
Retrieve data using Criteria api
1 Answer(s)      6 years ago
Posted in : Hibernate

import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Query; import org.hibernate.Criteria; import org.hibernate.criterion.Restrictions; import org.hibernate.cfg.Configuration; import java.util.*;

class ReadApplication { public static void main(String args[])throws Exception { Configuration configuration=new Configuration(); configuration.configure(); SessionFactory sf=configuration.buildSessionFactory(); Session s=sf.openSession(); Criteria criteria=s.createCriteria(Account.class); criteria.add(Restrictions.gt("balance",20000)); List<Account> l2=criteria.list(); for(Account acc:l2) { System.out.println("Account number "+acc.getAccno()+" detail....."); System.out.println(); System.out.println("Name : "+acc.getName()); System.out.println(); System.out.println("Balance : "+acc.getBalance()); //count++; } s.close(); } } And there is a Account class. when run this in command prompt i get some errors like... Jul 31, 2011 10:23:49 AM org.hibernate.type.NullableType nullSafeSet INFO: could not bind value '20000' to parameter: 1; java.lang.Integer Exception in thread "main" java.lang.ClassCastException: java.lang.Integer at org.hibernate.type.FloatType.set(FloatType.java:37) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65) at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514 ) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576) at org.hibernate.loader.Loader.doQuery(Loader.java:661) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Lo ader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2145) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java :94) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1533) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283) at ReadApplication.main(ReadApplication.java:33)

Ads
View Answers

August 1, 2011 at 11:38 AM


Please go through the following link:

Hibernate Tutorials


Ads









Related Tutorials/Questions & Answers:
Retrieve data using Criteria api
Retrieve data using Criteria api  import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Query; import...=configuration.buildSessionFactory(); Session s=sf.openSession(); Criteria criteria
Hibernate: ORDER BY using Criteria API.
Hibernate: ORDER BY using Criteria API.  How to display record in order using Criteria API?   Hibernate Criteria API provides an easy way... API is very Simplified API for fetching data from Criterion objects. The criteria
Advertisements
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
retrieve data from database using jsf
retrieve data from database using jsf  Hello I want an example of source code to retrieve data from database i have a database (oracle) name as db1...),, name ,and city I want after enter value in textbox according idauthor i retrieve
Retrieve data from xml using servlets
Retrieve data from xml using servlets  Hi plz send me the code for retrieving the data from xml File using Servlets.   Hi, Do you want.... Thanks Deepak   Hi, Here is one tutorial: Create XML File using Servlet
Retrieve data from databse using where in JSP
Retrieve data from databse using where in JSP  Hi, can somebody help me? I have a jsp page. in that i want to get data from the database where username is matched. i tried it. but can't get the output. here is the code. please
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
What is criteria API?
on the persistence database. The hibernate criteria API is very Simplified API for fetching data from Criterion objects. The Hibernate Criteria API contains Restriction class... What is criteria API?  Hi, What is criteria API? Thanks,  
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box ,the related employee name will be displayed in text field
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use
Hibernate Criteria API
data from Criterion objects. The criteria API is an alternative of HQL... criteria functions and dynamic queries. Using Criteria API to create...Hibernate Criteria API The API (Application Programming Interface
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to retrieve data using combo box value in jsp?  Hi freind, I already post this question. I need urgent help from u. pl response me.... All actions in the same page.......  Hi Friend, Please visit
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  Hi Friends... related value.... I am using only this page.. not get value from another page... in combo box from database.. by using select*from studentinformation; But when i
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ... for retrieving data fromm two tables : first table having fields: bookid,name,phno second table having field: seat-id But the data is not retrieved:why so
criteria api
criteria api  what is the purpose of Restrictions class   Using Restrictions class, we can narrow the result of our query.Here are some restrictions that can also be use to narrow our Criteria query result
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
Retrieve data from database by using sql tag of JSTL SQL library
Retrieve data from database by using sql tag of JSTL SQL library... we will see how retrieve data from database using sql query given by user. To execute query first create a data source and then execute sql query
how to store,retrieve,modify the data
how to store,retrieve,modify the data  hello sir ,how to store,retrieve,modify the data using the swing please help me
Using criteria for multiple tables
Using criteria for multiple tables  How to join more than three tables,those tables must be maintain primary key relation ship using Hql criteria & projections
Using criteria for multiple tables
Using criteria for multiple tables  How to join more than three tables,those tables must be maintain primary key relation ship using Hql criteria & projections
Retrieve data by clicking a link
Retrieve data by clicking a link  In a page there are 5 links.Every link has a hidden value. According to that hidden value data should be retrieved from the database and data should be displayed in a new page.How to do it?Please
sending data to google chart api from mysql database using java
sending data to google chart api from mysql database using java  how to send data from mysql database to google chart api using java
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
store and retrieve data
store and retrieve data  sir,i want to store the entering data in a word file and retrieve it when i need.i am try to develop a video portal.in which... Write data into word file For this, poi-scratchpad-3.7-20101029.jar is needed
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int),avdRed(float),avgGreen(float),avgBlue(float) i have to retrieve all the fields
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons  i have a database having columns id(int),path(text),width(int),height(int),avdRed(float),avgGreen(float),avgBlue(float) i have to retrieve all the fields