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


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Hibernate Hibernatefromclauseexample

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

33 comments so far (post your own) View All Comments Latest 10 Comments:

Hi,

Same error. Not able to iterate.

Hibernate: select insurance0_.ID as col_0_0_ from insurance insurance0_
java.lang.NullPointerException

Please suggest.

Regards,
Divya

Posted by Divya on Monday, 10.25.10 @ 10:09am | #100464

why we have to set session object to null initially?

Posted by ramesh on Thursday, 10.21.10 @ 10:48am | #100400

I've learnt a lot from this tutorial.
The examples all work perfectly.

Posted by Amruthesh C on Thursday, 10.14.10 @ 17:53pm | #100286

Too good Deepak. WGWWW - We got what we want

Posted by Swomya on Friday, 01.8.10 @ 14:20pm | #93884

I try to read from your pages, but keep getting interrupted by your redirects. Very annoying. Please take out the redirects.

Thanks.

Posted by ernest on Thursday, 11.19.09 @ 20:22pm | #92717

You must add command

query.list();

after the command
Query query = session.createQuery(SQL_QUERY);

then your program can execute.

Nam

Posted by Nam on Tuesday, 07.21.09 @ 07:17am | #89490

I NEED REGARDING HYBERNET

Posted by elakiya.a on Saturday, 12.27.08 @ 19:16pm | #83224

Hibernate: select insurance0_.ID as col_0_0_ from insurance insurance0_
ID: 1
why-->
Hibernate: select insurance0_.ID as ID0_, insurance0_.insurance_name as insurance2_2_0_, insurance0_.invested_amount as invested3_2_0_, insurance0_.investement_date as investem4_2_0_ from insurance insurance0_ where insurance0_.ID=?
could not load an entity: [roseindia.tutorial.hibernate.Insurance#1]

Any body got the same error and resolved coule be a greate help.....guys..

Posted by shyam on Wednesday, 08.20.08 @ 03:26am | #73850

hi,
I have got the same problem "commons-beanutils.jar" which is referenced by classpath does not exists.wheter it is properly placed .

regards
ravi

Posted by ravi on Tuesday, 02.12.08 @ 17:46pm | #48030

Dear Deepak,

When i run this example i found an error "commons-beanutils.jar" which is refrenced by ur classpath , does not exist.Wheter it is properly their.

Pls tell me as soon as possible.

Posted by ravi on Tuesday, 02.12.08 @ 17:43pm | #48028

for someone can not execute you can insert
some line same below

Query query = session.createQuery(SQL_QUERY);
System.out.println("query===" + query.list());

when i am insert line query.list()) this class run successfull

Posted by star... on Sunday, 01.20.08 @ 15:21pm | #45677

After running above program I get shown below error.
Please let me know what needs to done.

Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:27)

at org.hibernate.impl.SessionFactoryImpl.createQueryTranslators(SessionFactoryImpl.java:344)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:410)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:850)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
at SelectHQLExample.main(SelectHQLExample.java:27)

Posted by Godwin Ajit on Friday, 01.11.08 @ 08:10am | #44948

Please send details about levels of hibernate

Posted by mahesh on Thursday, 11.29.07 @ 16:16pm | #40887

After running above program I didnt get any result just showing below lines.
Please let me know what needs to done.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Before iterator
Hibernate: select insurance0_.ID as col_0_0_ from insurance insurance0_

Posted by syed on Tuesday, 11.27.07 @ 15:02pm | #40693

from Insurance insurance

in the above line, after 'from' there are 2 insurance words not sure the reason for this ? can they differ if so when and how and why..?

ANSWER : There we are taking the alias name for Table Insurance

Posted by Jagaidsh on Monday, 11.26.07 @ 04:30am | #40332

from Insurance insurance

in the above line, after 'from' there are 2 insurance words not sure the reason for this ? can they differ if so when and how and why..?

Posted by Anil on Thursday, 11.8.07 @ 22:23pm | #36710

I need to learn Hybernet topics

Posted by vijaykumar on Wednesday, 08.22.07 @ 17:06pm | #23913

When I run above example. I am getting following:
----------------
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
*******************************
Query using Hibernate Query Language
Hibernate: select insurance0_.ID as col_0_0_ from insurance insurance0_ where (insurance0_.ID='1')
could not execute query using iterate
------------------------------------

This is the same case for all the select queries. It always complain "Could not execute query using iterate". Can you please suggest me a solution?

Posted by Pradeep on Tuesday, 08.7.07 @ 02:44am | #22818

i want to insert data in table from a with intialization of a object. my class is mapped with another table

Posted by vivek jain on Wednesday, 07.25.07 @ 17:32pm | #21925

Not able to fetch rows.showing just the below message..
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select insurance0_.id as col_0_0_ from insurance insurance0_

Please help

Posted by ram on Saturday, 07.21.07 @ 06:08am | #21673

This tutorial gives good basics

Posted by Arjungosling on Sunday, 05.20.07 @ 22:02pm | #16837

Hi
Place the jta.jar in the classpath

Posted by xavier on Thursday, 05.17.07 @ 15:14pm | #16252


while try to run this prg it will display error like this:
but i cant uble to rectify it...
can any one do the needful..
public class Testhql {
public static void main(String[] args) {
Session session = null;

try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();


//Using from Clause
String SQL_QUERY ="from Insurance insurance";
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
Contact ct=(Contact)it.next();
System.out.println("ID: " + ct.getId());
System.out.println("First Name: " + ct.getFirstName());
}

session.close();
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
}

}
}

output:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
at org.hibernate.impl.SessionFactoryImpl.buildCurrentSessionContext(SessionFactoryImpl.java:999)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:334)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at techm.Testhql.main(Testhql.java:13)

Posted by hari on Thursday, 04.19.07 @ 15:27pm | #14560

in the query "from Insurance insurance" the first 'Insurance' refers to the class name of the table while the second is just the alias name for the class. The query "from Insurance" will also work fine for this program

Posted by Pawan Gupta on Thursday, 04.12.07 @ 15:15pm | #13956

String SQL_QUERY ="from Insurance insurance";

In the above statement what does mean the first and second Insurance.

If suppose first is the name of table then second means?

Posted by Subhash.P on Monday, 04.2.07 @ 18:44pm | #13203

hi i am new to hibernate i can insert data to db through session.save() but i am not able to use the quieries here is the sample code and the exception

package com.allo.cem.test;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.allo.cem.mapping.UserDetails;
import com.allo.cem.sessionFactory.HibernateSessionFactory;

public class test2 {
private static Session session;

public static void main(String args[]) {
setUp();
getAllUser();
tearDown();
}

private static void getAllUser() {


Transaction tx = session.beginTransaction();
String SQL = "select * from user_details";
Query query = session.createQuery(SQL);
List list = query.list();

Iterator iterator = list.iterator();
while (iterator.hasNext()) {
UserDetails userDetails = (UserDetails) iterator.next();
System.out.println("THE USER NAME :" + userDetails.getUserName());
}

tx.commit();
}

private static void tearDown() {
HibernateSessionFactory.closeSession();
}

private static void setUp() {
session = HibernateSessionFactory.currentSession();
}
}




************* exception **********************
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxError: unexpected token: * near line 1, column 8 [select * from user_details]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:215)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.allo.cem.test.test2.getAllUser(test2.java:28)
at com.allo.cem.test.test2.main(test2.java:18)
Caused by: line 1:8: unexpected token: *
at org.hibernate.hql.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:962)
at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:735)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:611)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:263)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:150)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:209)
... 8 more

Posted by sachin on Friday, 03.30.07 @ 11:20am | #12973

Hello,

I have imported these tutorial into Rational software architect and get the examples that are inserting data into database working. But the example 'SelectHQLExample' that reads from insurance table is returning zero rows. But infact the table has more rows in the database. Any clue?

Thanks
Prasad

Posted by prasad on Tuesday, 03.20.07 @ 07:52am | #12233

this rows-india is usefull for the beginners
its really working

Posted by swarna on Thursday, 02.15.07 @ 13:30pm | #7955

The first one is the table name and the second one is the alias of the table-name.

Posted by Peter on Wednesday, 01.31.07 @ 23:25pm | #5002

String SQL_QUERY ="from Insurance insurance";

In the above statement what does mean the first and second Insurance

Posted by neeraja on Wednesday, 01.17.07 @ 11:56am | #3659

String SQL_QUERY ="from Insurance insurance";

In the above statement what does mean the first and second Insurance.

If suppose first is the name of table then second means?

Posted by bhushan on Wednesday, 01.10.07 @ 12:23pm | #3104

String SQL_QUERY ="from Insurance insurance";

In the above statement what does mean the first and second Insurance.

If suppose first is the name of table then second means?

Posted by Birender Singh on Wednesday, 12.20.06 @ 10:56am | #1307

It's amazing example for using hibernate.

How about master-detail relationship Mr.Deepak??
Could you give us a simple example how to solve the
problem in hibernate env. Thx

Posted by Leevy on Sunday, 12.10.06 @ 11:16am | #725

Ask programming questions?

 

 

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
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  | Site Map

India News

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

Copyright 2007. All rights reserved.