-->
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.  [ 2 posts ] 
Author Message
 Post subject: I'm not able to use createquery
PostPosted: Fri Sep 19, 2003 5:13 am 
Newbie

Joined: Fri Sep 19, 2003 5:06 am
Posts: 4
Hi all,
I'm very new to hibernate and I'm trying a simple program to get it working.
I have an oracle db and I put a table db_obj in it.
here is my hibernate xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>

<!-- <property name="connection.datasource">java:comp/env/jdbc/quickstart</property> -->
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@server:1521:ORCL</property>
<property name="connection.username">xxxx</property>
<property name="connection.password">xxxx</property>

<!-- Mapping files -->
<mapping resource="dbobj.hbm.xml"/>

</session-factory>

</hibernate-configuration>

and here is my dbobj.nbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="it.noematica.DbObj" table="db_obj">
<id name="id" type="integer" unsaved-value="null" >
<column name="OBJECT_ID" sql-type="integer" not-null="true"/>
<generator class="assigned"/>
</id>

<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="owner" not-null="true"/>
<property name="objectName" column="OBJECT_NAME" not-null="true"/>
<property name="subobjectName" column="SUBOBJECT_NAME" />
<property name="dataObjectId" type="integer" column="DATA_OBJECT_ID" not-null="true"/>
<property name="objectType" column="OBJECT_TYPE" />
<property name="created" type="timestamp" column="CREATED" not-null="true"/>
<property name="lastDDLTime" type="timestamp" column="LAST_DDL_TIME" not-null="true"/>
<property name="timestamp" column="TIMESTAMP" />
<property name="status" column="STATUS" />
<property name="temporary" column="TEMPORARY" />
<property name="generated" column="GENERATED" />
<property name="secondary" column="SECONDARY" />
</class>

</hibernate-mapping>

here is the sample I used

package it.noematica;

import java.util.Iterator;
import java.util.List;
import java.sql.Connection;
import java.sql.DriverManager;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;

public class HibernateTest {
public static void main(String[] args)throws Exception {
HibernateTest hibernateTest = new HibernateTest();

SessionFactory factory=new Configuration().configure().buildSessionFactory();
Session session=factory.openSession();
session.beginTransaction();
Query query=session.createQuery("from db_obj");
for (Iterator it = query.iterate(); it.hasNext();) {
DbObj dbobj = (DbObj) it.next();
System.out.println("dbobj: name " + dbobj.getObjectName());
}

}
}

when I try tro execute I got this error:
[INFO] Environment - -Hibernate 2.0.3

[INFO] Environment - -hibernate.properties not found

[INFO] Environment - -using CGLIB reflection optimizer

[INFO] Environment - -JVM proxy support: true

[INFO] Configuration - -Configuration resource: /hibernate.cfg.xml

[INFO] Configuration - -Mapping resource: dbobj.hbm.xml

[INFO] Binder - -Mapping class: it.noematica.DbObj -> db_obj

[INFO] Configuration - -Configured SessionFactory: null

[INFO] Configuration - -processing one-to-many association mappings

[INFO] Configuration - -processing foreign key constraints

[INFO] SessionFactoryImpl - -building session factory

[INFO] Dialect - -Using dialect: net.sf.hibernate.dialect.OracleDialect

[INFO] DriverManagerConnectionProvider - -Hibernate connection pool size: 20

[INFO] DriverManagerConnectionProvider - -using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@server:1521:ORCL

[INFO] DriverManagerConnectionProvider - -connection properties: {user=xxxx, password=xxxx}

[INFO] SessionFactoryImpl - -Use outer join fetching: false

[INFO] SessionFactoryImpl - -Use scrollable result sets: true

[INFO] SessionFactoryImpl - -JDBC 2 max batch size: 15

[INFO] SessionFactoryImpl - -echoing all SQL to stdout

Hibernate: select from

[INFO] SessionFactoryObjectFactory - -no JDNI name configured

[INFO] SessionFactoryImpl - -Query language substitutions: {}

[WARN] JDBCExceptionReporter - -SQL Error: 936, SQLState: 42000

[ERROR] JDBCExceptionReporter - -ORA-00936: espressione mancante


[ERROR] JDBCExceptionReporter - -Could not execute query <java.sql.SQLException: ORA-00936: espressione mancante
>java.sql.SQLException: ORA-00936: espressione mancante

I think I'm missing something obvious but I'm not able to get rid of it.
Thanks in advance,
Giovanni


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2003 5:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Query query=session.createQuery("from db_obj");

This is not a valid HQL query. Try "from it.noematica.DbObj as dbobj" and remember you are not writing SQL here, no table names or column names, only classes, their properties and aliases. Check the documentation chapter about HQL.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.