Magazine
 
Hibernate Query Language

}
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());
}
}
}

Here is the code for Product.java to set the class’s objects with the table’s fields. package javajzzup.hibernate;

public class Product {
private int id;
private String name;
private double price;
private Dealer dealer;
private int did;
public Product(String name, double price)
{
super();
// TODO Auto-generated constructor stub
this.name = name;
this.price = price;
}
public Product() {
super();
// TODO Auto-generated constructor stub
}
public Dealer getDealer() {
return dealer;
}
public void setDealer(Dealer dealer) {
this.dealer = dealer;
}
public double getDid() {
return did;
}

 

public void setDid(int did) {
this.did = did;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}

The output of this program will be shown as:

log4j:WARN No appenders could be found for
logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system
properly.
Hibernate: select this_.name as y0_,
this_.price as y1_ from Product this_
Product Name Price
Computer 23000.0
Mobile 15000.0
Laptop 200.0
Keyboard 1500.0
PenDrive 200.0
HardDisk 2500.0

Download example

5. Order
The Order class defined in the org.hibernate.criterion package represents the “order by” clause of SQL. By using the asc() and desc() methods of this class, order can be imposed upon the Criteria resultselt.

Mar 2008 | Java Jazz Up | 50
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59,

Download PDF