-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: just simple SELECT
PostPosted: Wed Jun 28, 2006 11:04 am 
Beginner
Beginner

Joined: Thu Jun 22, 2006 8:56 am
Posts: 22
Hallo,

i am new to Hibernate and i dont really know where the problem is. I wanted to execute just a simple SQL statement.
My debug informations end with: DriverManagerConnectionProvider:109 - opening new JDBC connection
Can anyoune help me ?

Thank you
seven-12


Hibernate version:3

Mapping documents:<?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="Error" table="hibertest">
<id name="id" column="errorid">
<generator class="native"/>
</id>
<property name="timestamp" type="timestamp" column="LOGDATE"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

ArrayList arrayList = null;

String SQL_STRING = "FROM hibertest";
Query query = session.createQuery(SQL_STRING);
System.out.println(query);
ArrayList list = (ArrayList)query.list();

for(int i=0; i<list.size();i++){
System.out.println(list.get(i));
}




Debug level Hibernate log excerpt:

my debug informations end with: 10:59:11,667 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 11:34 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I dont have enough information from your post but your code should be as follows

Code:
String SQL_STRING = "FROM Error";
Query query = session.createQuery( SQL_STRING );
System.out.println( query );
List list = query.list();

for(int i=0; i<list.size();i++){
    System.out.println(list.get(i));
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 2:16 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
bkmr_77 wrote:
I dont have enough information from your post but your code should be as follows

Code:
String SQL_STRING = "FROM Error";
Query query = session.createQuery( SQL_STRING );
System.out.println( query );
List list = query.list();

for(int i=0; i<list.size();i++){
    System.out.println(list.get(i));
}

I agree, there's not enough info to help him.

I would just change the first line of the above code to
Code:
final String HQL_STRING = "FROM Error";
because this is HQL and not SQL, so it could lead beginners to mistakes...

In fact, in you want to execute SQL directly, it's session.createSQLQuery(), but I'd recommend to try to use SQL as little as possible. In fact, it's better to use HQL or Criteria API because the queries are Object Oriented, instead of DB oriented.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.