Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

hi i m new to hibernate..plzzzzzzzzzzzzzz help me....
Expert:poonam
hi friends i m new to hibernate..& i m stuck in one positon in my pgm..
its a simple select query which i wan to run...with oracle thin database connection...............

//********** cfg file*********

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="session">
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@172.16.31.25:1521:BOMBAY</property>
<property name="hibernate.connection.username">poonam</property>
<property name="hibernate.connection.password">poonam</property>
<!-- Set AutoCommit to true -->
<property name="connection.autocommit">true</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>


///******hbm file**********

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="indiabulls.test.Contact" table="CONTACT">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>

<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>
</hibernate-mapping>


//*******Java bean **********

package indiabulls.test;

public class Contact
{
private String firstName;
private String lastName;
private String email;
private int id;

public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getEmail()
{
return email;
}
public void setEmail(String email)
{
this.email = email;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
}


//******SelectExample.java******

package indiabulls.test;

import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;
public class SelectExample
{
public void getdata()
{ Session session = null;
try
{
System.out.println("lj;kj");
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("********CONNECTION MADE***********");

String SQL_QUERY = "from Contact contact";

Query query = session.createQuery(SQL_QUERY);
System.out.println("SQL_QUERY"+SQL_QUERY);
Iterator it=query.iterate();
while(it.hasNext())
{
//System.out.println("******* " +it.next());
Contact contact=(Contact)it.next();
// Object[] row = (Object[]) it.next();
// System.out.println("ID: " + contact.getId());
System.out.println("LastName: " + contact.getLastName());
//System.out.println("Email: " + contact.getEmail());
}
System.out.println("*******Done********");
session.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}

public static void main(String[] args)
{
SelectExample s=new SelectExample();
s.getdata();
}

}


its showing 1st column that is ID column..but not showing the other
values of firstname,LastName,email......
plzzzzzzzzzzzzzzz help me whats the problem...
its showing me

//************Error*********

could not load an entity: [indiabulls.test.Contact#24]
Answers
Hi poonam

This is wrong query. you are using wrong query.

String SQL_QUERY = "from Contact contact";



Read for more information.

http://www.roseindia.net/hibernate/selectclause.shtml



Thanks.

hi deepak..
when i change my query ...
now its showing me this error...
plz help me.....

MY PRG IS::::::::::

package indiabulls.test;

import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;
public class SelectExample
{
public void getdata()
{ Session session = null;
try
{
System.out.println("lj;kj");
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
System.out.println("********CONNECTION MADE***********");
String SQL_QUERY = "Select contact.id, contact.firstName, contact.lastName, contact.email from Contact contact";
//String SQL_QUERY = "from indiabulls.test.Contact contact";

Query query = session.createQuery(SQL_QUERY);
System.out.println("SQL_QUERY : "+SQL_QUERY);
Iterator it=query.iterate();
while(it.hasNext())
{
//System.out.println("******* " +it.next());
Contact contact=(Contact)it.next();
// Object[] row = (Object[]) it.next();
System.out.println("ID: " + contact.getId());
System.out.println("LastName: " + contact.getLastName());
System.out.println("Email: " + contact.getEmail());
}
System.out.println("*******Done********");
session.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}

public static void main(String[] args)
{
SelectExample s=new SelectExample();
s.getdata();
}

}


ERROR:::::::

SQL_QUERY : Select contact.id, contact.firstName, contact.lastName, contact.email from Contact contact
could not execute query using iterate

now its showing that this query cant be executed

More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.